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