1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorexecute.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
32 #define INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
34 //===============================================
37 #include "svtools/svtdllapi.h"
39 #ifndef INCLUDED_VECTOR
41 #define INCLUDED_VECTOR
44 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #ifndef __COM_SUN_STAR_FRAME_XFRAME_HPP_
49 #include <com/sun/star/frame/XFrame.hpp>
52 #ifndef __COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
53 #include <com/sun/star/frame/XDispatchProvider.hpp>
56 #ifndef __com_SUN_STAR_UI_XACCELERATORCONFIGURATION_HPP_
57 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
60 #ifndef __COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
61 #include <com/sun/star/util/XURLTransformer.hpp>
63 #include <com/sun/star/util/URL.hpp>
65 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
66 #include <com/sun/star/awt/KeyEvent.hpp>
68 #include <vcl/keycod.hxx>
69 #include <vcl/evntpost.hxx>
70 #include <osl/mutex.h>
72 //===============================================
76 #error "Conflict on using css as namespace alias!"
78 #define css ::com::sun::star
84 //===============================================
92 //===============================================
94 @descr implements a helper, which can be used to
95 convert vcl key codes into awt key codes ...
98 Further such key code can be triggered.
99 Doing so different accelerator
100 configurations are merged together; a suitable
101 command registered for the given key code is searched
102 and will be dispatched.
106 Because exceution of an accelerator command can be dangerous
107 (in case it force an office shutdown for key "ALT+F4"!)
108 all internal dispatches are done asynchronous.
109 Menas that the trigger call doesnt wait till the dispatch
110 is finished. You can call very often. All requests will be
111 queued internal and dispatched ASAP.
113 Of course this queue will be stopped if the environment
114 will be destructed ...
116 class SVT_DLLPUBLIC AcceleratorExecute
: private TMutexInit
118 //-------------------------------------------
123 replaced by internal class AsyncAccelExec ...
124 remove this resource here if we go forwards to next major */
125 typedef ::std::vector
< ::std::pair
< css::util::URL
, css::uno::Reference
< css::frame::XDispatch
> > > TCommandQueue
;
127 //-------------------------------------------
131 /** TODO document me */
132 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
134 /** TODO document me */
135 css::uno::Reference
< css::util::XURLTransformer
> m_xURLParser
;
137 /** TODO document me */
138 css::uno::Reference
< css::frame::XDispatchProvider
> m_xDispatcher
;
140 /** TODO document me */
141 css::uno::Reference
< css::ui::XAcceleratorConfiguration
> m_xGlobalCfg
;
142 css::uno::Reference
< css::ui::XAcceleratorConfiguration
> m_xModuleCfg
;
143 css::uno::Reference
< css::ui::XAcceleratorConfiguration
> m_xDocCfg
;
146 replaced by internal class AsyncAccelExec ...
147 remove this resource here if we go forwards to next major */
148 TCommandQueue m_lCommandQueue
;
151 replaced by internal class AsyncAccelExec ...
152 remove this resource here if we go forwards to next major */
153 ::vcl::EventPoster m_aAsyncCallback
;
155 //-------------------------------------------
159 //---------------------------------------
160 /** @short factory method to create new accelerator
163 @descr Such helper instance must be initialized at first.
164 So it can know its environment (global/module or
167 Afterwards it can be used to execute incoming
168 accelerator requests.
170 The "end of life" of such helper can be reached as follow:
173 => If it stands currently in its execute method, they will
174 be finished. All further queued requests will be removed
175 and further not executed!
177 - "let it stay alone"
178 => All currently queued events will be finished. The
179 helper kills itself afterwards. A shutdown of the
180 environment will be recognized ... The helper stop its
181 work immediatly then!
183 static AcceleratorExecute
* createAcceleratorHelper();
185 //---------------------------------------
186 /** @short fight against inlining ... */
187 virtual ~AcceleratorExecute();
189 //---------------------------------------
190 /** @short init this instance.
192 @descr It must be called as first method after creation.
193 And further it can be called more then once ...
194 but at least its should be used one times only.
195 Otherwhise nobody can say, which asynchronous
196 executions will be used inside the old and which one
197 will be used inside the new environment.
200 reference to an uno service manager.
203 if it points to a valid frame it will be used
204 to execute the dispatch there. Further the frame
205 is used to locate the right module configuration
206 and use it merged together with the document and
207 the global configuration.
209 If this parameter is set to NULL, the global configuration
210 is used only. Further the global Desktop instance is
213 virtual void init(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
214 const css::uno::Reference
< css::frame::XFrame
>& xEnv
);
216 //---------------------------------------
217 /** @short trigger this accelerator.
219 @descr The internal configuartions are used to find
220 as suitable command for this key code.
221 This command will be queued and executed later
225 specify the accelerator for execute.
228 TRUE if this key is configured and match to a command.
229 Attention: This state does not mean the success state
230 of the corresponding execute. Because its done asynchronous!
232 virtual sal_Bool
execute(const KeyCode
& aKey
);
233 virtual sal_Bool
execute(const css::awt::KeyEvent
& aKey
);
235 /** search the command for the given key event.
237 * @param aKey The key event
238 * @return The command or an empty string if the key event could not be found.
240 ::rtl::OUString
findCommand(const ::com::sun::star::awt::KeyEvent
& aKey
);
241 //---------------------------------------
242 /** TODO document me */
243 static css::awt::KeyEvent
st_VCLKey2AWTKey(const KeyCode
& aKey
);
244 static KeyCode
st_AWTKey2VCLKey(const css::awt::KeyEvent
& aKey
);
246 //---------------------------------------
247 /** TODO document me */
248 static css::uno::Reference
< css::ui::XAcceleratorConfiguration
> st_openGlobalConfig(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
250 //---------------------------------------
251 /** TODO document me */
252 static css::uno::Reference
< css::ui::XAcceleratorConfiguration
> st_openModuleConfig(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
253 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
255 //---------------------------------------
256 /** TODO document me */
257 static css::uno::Reference
< css::ui::XAcceleratorConfiguration
> st_openDocConfig(const css::uno::Reference
< css::frame::XModel
>& xModel
);
259 //-------------------------------------------
263 //---------------------------------------
264 /** @short allow creation of instances of this class
265 by using our factory only!
267 SVT_DLLPRIVATE
AcceleratorExecute();
269 AcceleratorExecute(const AcceleratorExecute
& rCopy
);
270 void operator=(const AcceleratorExecute
&) {};
271 //---------------------------------------
272 /** TODO document me */
273 SVT_DLLPRIVATE ::rtl::OUString
impl_ts_findCommand(const css::awt::KeyEvent
& aKey
);
275 //---------------------------------------
276 /** TODO document me */
277 SVT_DLLPRIVATE
css::uno::Reference
< css::util::XURLTransformer
> impl_ts_getURLParser();
279 //---------------------------------------
281 replaced by internal class AsyncAccelExec ...
282 remove this resource here if we go forwards to next major */
283 DECL_DLLPRIVATE_LINK(impl_ts_asyncCallback
, void*);
290 #endif // INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX