Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
21 : #define INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
22 :
23 : #include "svtools/svtdllapi.h"
24 :
25 : #include <vector>
26 :
27 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 : #include <com/sun/star/uno/XComponentContext.hpp>
29 : #include <com/sun/star/frame/XFrame.hpp>
30 : #include <com/sun/star/frame/XDispatchProvider.hpp>
31 : #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
32 : #include <com/sun/star/util/XURLTransformer.hpp>
33 : #include <com/sun/star/util/URL.hpp>
34 : #include <com/sun/star/awt/KeyEvent.hpp>
35 : #include <vcl/keycod.hxx>
36 : #include <vcl/evntpost.hxx>
37 : #include <osl/mutex.h>
38 :
39 :
40 : namespace svt
41 : {
42 :
43 :
44 0 : struct TMutexInit
45 : {
46 : ::osl::Mutex m_aLock;
47 : };
48 :
49 : //===============================================
50 : /**
51 : @descr implements a helper, which can be used to
52 : convert vcl key codes into awt key codes ...
53 : and reverse.
54 :
55 : Further such key code can be triggered.
56 : Doing so different accelerator
57 : configurations are merged together; a suitable
58 : command registered for the given key code is searched
59 : and will be dispatched.
60 :
61 : @attention
62 :
63 : Because exceution of an accelerator command can be dangerous
64 : (in case it force an office shutdown for key "ALT+F4"!)
65 : all internal dispatches are done asynchronous.
66 : Menas that the trigger call doesnt wait till the dispatch
67 : is finished. You can call very often. All requests will be
68 : queued internal and dispatched ASAP.
69 :
70 : Of course this queue will be stopped if the environment
71 : will be destructed ...
72 : */
73 : class SVT_DLLPUBLIC AcceleratorExecute : private TMutexInit
74 : {
75 : //-------------------------------------------
76 : // const, types
77 : private:
78 :
79 : /** @deprecated
80 : replaced by internal class AsyncAccelExec ...
81 : remove this resource here if we go forwards to next major */
82 : typedef ::std::vector< ::std::pair< css::util::URL, css::uno::Reference< css::frame::XDispatch > > > TCommandQueue;
83 :
84 : //-------------------------------------------
85 : // member
86 : private:
87 :
88 : /** TODO document me */
89 : css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
90 :
91 : /** TODO document me */
92 : css::uno::Reference< css::util::XURLTransformer > m_xURLParser;
93 :
94 : /** TODO document me */
95 : css::uno::Reference< css::frame::XDispatchProvider > m_xDispatcher;
96 :
97 : /** TODO document me */
98 : css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalCfg;
99 : css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleCfg;
100 : css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocCfg;
101 :
102 : /** @deprecated
103 : replaced by internal class AsyncAccelExec ...
104 : remove this resource here if we go forwards to next major */
105 : TCommandQueue m_lCommandQueue;
106 :
107 : /** @deprecated
108 : replaced by internal class AsyncAccelExec ...
109 : remove this resource here if we go forwards to next major */
110 : ::vcl::EventPoster m_aAsyncCallback;
111 :
112 : //-------------------------------------------
113 : // interface
114 : public:
115 :
116 : //---------------------------------------
117 : /** @short factory method to create new accelerator
118 : helper instance.
119 :
120 : @descr Such helper instance must be initialized at first.
121 : So it can know its environment (global/module or
122 : document specific).
123 :
124 : Afterwards it can be used to execute incoming
125 : accelerator requests.
126 :
127 : The "end of life" of such helper can be reached as follow:
128 :
129 : - delete the object
130 : => If it stands currently in its execute method, they will
131 : be finished. All further queued requests will be removed
132 : and further not executed!
133 :
134 : - "let it stay alone"
135 : => All currently queued events will be finished. The
136 : helper kills itself afterwards. A shutdown of the
137 : environment will be recognized ... The helper stop its
138 : work immediatly then!
139 : */
140 : static AcceleratorExecute* createAcceleratorHelper();
141 :
142 : //---------------------------------------
143 : /** @short fight against inlining ... */
144 : virtual ~AcceleratorExecute();
145 :
146 : //---------------------------------------
147 : /** @short init this instance.
148 :
149 : @descr It must be called as first method after creation.
150 : And further it can be called more then once ...
151 : but at least its should be used one times only.
152 : Otherwhise nobody can say, which asynchronous
153 : executions will be used inside the old and which one
154 : will be used inside the new environment.
155 :
156 : @param xSMGR
157 : reference to an uno service manager.
158 :
159 : @param xEnv
160 : if it points to a valid frame it will be used
161 : to execute the dispatch there. Further the frame
162 : is used to locate the right module configuration
163 : and use it merged together with the document and
164 : the global configuration.
165 :
166 : If this parameter is set to NULL, the global configuration
167 : is used only. Further the global Desktop instance is
168 : used for dispatch.
169 : */
170 : virtual void init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR,
171 : const css::uno::Reference< css::frame::XFrame >& xEnv );
172 :
173 : //---------------------------------------
174 : /** @short trigger this accelerator.
175 :
176 : @descr The internal configuartions are used to find
177 : as suitable command for this key code.
178 : This command will be queued and executed later
179 : asynchronous.
180 :
181 : @param aKey
182 : specify the accelerator for execute.
183 :
184 : @return [sal_Bool]
185 : sal_True if this key is configured and match to a command.
186 : Attention: This state does not mean the success state
187 : of the corresponding execute. Because its done asynchronous!
188 : */
189 : virtual sal_Bool execute(const KeyCode& aKey);
190 : virtual sal_Bool execute(const css::awt::KeyEvent& aKey);
191 :
192 : /** search the command for the given key event.
193 : *
194 : * @param aKey The key event
195 : * @return The command or an empty string if the key event could not be found.
196 : */
197 : ::rtl::OUString findCommand(const ::com::sun::star::awt::KeyEvent& aKey);
198 : //---------------------------------------
199 : /** TODO document me */
200 : static css::awt::KeyEvent st_VCLKey2AWTKey(const KeyCode& aKey);
201 : static KeyCode st_AWTKey2VCLKey(const css::awt::KeyEvent& aKey);
202 :
203 : //---------------------------------------
204 : /** TODO document me */
205 : static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openGlobalConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
206 :
207 : //---------------------------------------
208 : /** TODO document me */
209 : static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openModuleConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext ,
210 : const css::uno::Reference< css::frame::XFrame >& xFrame);
211 :
212 : //---------------------------------------
213 : /** TODO document me */
214 : static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openDocConfig(const css::uno::Reference< css::frame::XModel >& xModel);
215 :
216 : //-------------------------------------------
217 : // internal
218 : private:
219 :
220 : //---------------------------------------
221 : /** @short allow creation of instances of this class
222 : by using our factory only!
223 : */
224 : SVT_DLLPRIVATE AcceleratorExecute();
225 :
226 : AcceleratorExecute(const AcceleratorExecute& rCopy);
227 : void operator=(const AcceleratorExecute&) {};
228 : //---------------------------------------
229 : /** TODO document me */
230 : SVT_DLLPRIVATE ::rtl::OUString impl_ts_findCommand(const css::awt::KeyEvent& aKey);
231 :
232 : //---------------------------------------
233 : /** TODO document me */
234 : SVT_DLLPRIVATE css::uno::Reference< css::util::XURLTransformer > impl_ts_getURLParser();
235 :
236 : //---------------------------------------
237 : /** @deprecated
238 : replaced by internal class AsyncAccelExec ...
239 : remove this resource here if we go forwards to next major */
240 : DECL_DLLPRIVATE_LINK(impl_ts_asyncCallback, void*);
241 : };
242 :
243 : } // namespace svt
244 :
245 : #endif // INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|