1f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e07b45SAndrew Rist  * distributed with this work for additional information
6f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f8e07b45SAndrew Rist  *
11f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f8e07b45SAndrew Rist  *
13f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18f8e07b45SAndrew Rist  * under the License.
19f8e07b45SAndrew Rist  *
20f8e07b45SAndrew Rist  *************************************************************/
21f8e07b45SAndrew Rist 
22f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
25cdf0e10cSrcweir #define INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //===============================================
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
33cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XFRAME_HPP_
37cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
41cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UI_XACCELERATORCONFIGURATION_HPP_
45cdf0e10cSrcweir #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
49cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
53cdf0e10cSrcweir #include <com/sun/star/awt/KeyEvent.hpp>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir #include <vcl/keycod.hxx>
56cdf0e10cSrcweir #include <vcl/evntpost.hxx>
57cdf0e10cSrcweir #include <osl/mutex.h>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //===============================================
60cdf0e10cSrcweir // namespace
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace svt
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #ifdef css
66cdf0e10cSrcweir     #error "Who define css? I need it as namespace alias."
67cdf0e10cSrcweir #else
68cdf0e10cSrcweir     #define css ::com::sun::star
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //===============================================
72cdf0e10cSrcweir // definitions
73cdf0e10cSrcweir 
74cdf0e10cSrcweir struct TMutexInit
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     ::osl::Mutex m_aLock;
77cdf0e10cSrcweir };
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //===============================================
80cdf0e10cSrcweir /**
81cdf0e10cSrcweir     @descr  implements a helper, which can be used to
82cdf0e10cSrcweir             convert vcl key codes into awt key codes ...
83cdf0e10cSrcweir             and reverse.
84cdf0e10cSrcweir 
85cdf0e10cSrcweir             Further such key code can be triggered.
86cdf0e10cSrcweir             Doing so different accelerator
87cdf0e10cSrcweir             configurations are merged together; a suitable
88cdf0e10cSrcweir             command registered for the given key code is searched
89cdf0e10cSrcweir             and will be dispatched.
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     @attention
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             Because exceution of an accelerator command can be dangerous
94cdf0e10cSrcweir             (in case it force an office shutdown for key "ALT+F4"!)
95cdf0e10cSrcweir             all internal dispatches are done asynchronous.
96*07a3d7f1SPedro Giffuni             Menas that the trigger call doesn't wait till the dispatch
97cdf0e10cSrcweir             is finished. You can call very often. All requests will be
98cdf0e10cSrcweir             queued internal and dispatched ASAP.
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             Of course this queue will be stopped if the environment
101cdf0e10cSrcweir             will be destructed ...
102cdf0e10cSrcweir  */
103cdf0e10cSrcweir class AcceleratorExecute : private TMutexInit
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     //-------------------------------------------
106cdf0e10cSrcweir     // const, types
107cdf0e10cSrcweir     private:
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         /** TODO document me */
110cdf0e10cSrcweir         typedef ::std::vector< ::rtl::OUString > TCommandQueue;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     //-------------------------------------------
113cdf0e10cSrcweir     // member
114cdf0e10cSrcweir     private:
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         /** TODO document me */
117cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         /** TODO document me */
120cdf0e10cSrcweir         css::uno::Reference< css::util::XURLTransformer > m_xURLParser;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         /** TODO document me */
123cdf0e10cSrcweir         css::uno::Reference< css::frame::XDispatchProvider > m_xDispatcher;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         /** TODO document me */
126cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalCfg;
127cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleCfg;
128cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocCfg;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         /** TODO document me */
131cdf0e10cSrcweir         TCommandQueue m_lCommandQueue;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         /** TODO document me */
134cdf0e10cSrcweir         ::vcl::EventPoster m_aAsyncCallback;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     //-------------------------------------------
137cdf0e10cSrcweir     // interface
138cdf0e10cSrcweir     public:
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         //---------------------------------------
141cdf0e10cSrcweir         /** @short  factory method to create new accelerator
142cdf0e10cSrcweir                     helper instance.
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             @descr  Such helper instance must be initialized at first.
145cdf0e10cSrcweir                     So it can know its environment (global/module or
146cdf0e10cSrcweir                     document specific).
147cdf0e10cSrcweir 
148cdf0e10cSrcweir                     Afterwards it can be used to execute incoming
149cdf0e10cSrcweir                     accelerator requests.
150cdf0e10cSrcweir 
151cdf0e10cSrcweir                     The "end of life" of such helper can be reached as follow:
152cdf0e10cSrcweir 
153cdf0e10cSrcweir                     - delete the object
154cdf0e10cSrcweir                       => If it stands currently in its execute method, they will
155cdf0e10cSrcweir                          be finished. All further queued requests will be removed
156cdf0e10cSrcweir                          and further not executed!
157cdf0e10cSrcweir 
158cdf0e10cSrcweir                     Other modes are possible and will be implemented ASAP :-)
159cdf0e10cSrcweir          */
160cdf0e10cSrcweir         static AcceleratorExecute* createAcceleratorHelper();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         //---------------------------------------
163cdf0e10cSrcweir         /** @short  fight against inlining ... */
164cdf0e10cSrcweir         virtual ~AcceleratorExecute();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         //---------------------------------------
167cdf0e10cSrcweir         /** @short  init this instance.
168cdf0e10cSrcweir 
169cdf0e10cSrcweir             @descr  It must be called as first method after creation.
170cdf0e10cSrcweir                     And further it can be called more then once ...
171cdf0e10cSrcweir                     but at least its should be used one times only.
172cdf0e10cSrcweir                     Otherwhise nobody can say, which asynchronous
173cdf0e10cSrcweir                     executions will be used inside the old and which one
174cdf0e10cSrcweir                     will be used inside the new environment.
175cdf0e10cSrcweir 
176cdf0e10cSrcweir             @param  xSMGR
177cdf0e10cSrcweir                     reference to an uno service manager.
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             @param  xEnv
180cdf0e10cSrcweir                     if it points to a valid frame it will be used
181cdf0e10cSrcweir                     to execute the dispatch there. Further the frame
182cdf0e10cSrcweir                     is used to locate the right module configuration
183cdf0e10cSrcweir                     and use it merged together with the document and
184cdf0e10cSrcweir                     the global configuration.
185cdf0e10cSrcweir 
186cdf0e10cSrcweir                     If this parameter is set to NULL, the global configuration
187cdf0e10cSrcweir                     is used only. Further the global Desktop instance is
188cdf0e10cSrcweir                     used for dispatch.
189cdf0e10cSrcweir          */
190cdf0e10cSrcweir         virtual void init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR,
191cdf0e10cSrcweir                           const css::uno::Reference< css::frame::XFrame >&              xEnv );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         //---------------------------------------
194cdf0e10cSrcweir         /** @short  trigger this accelerator.
195cdf0e10cSrcweir 
196cdf0e10cSrcweir             @descr  The internal configuartions are used to find
197cdf0e10cSrcweir                     as suitable command for this key code.
198cdf0e10cSrcweir                     This command will be queued and executed later
199cdf0e10cSrcweir                     asynchronous.
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             @param  aKey
202cdf0e10cSrcweir                     specify the accelerator for execute.
203cdf0e10cSrcweir          */
204cdf0e10cSrcweir         virtual void execute(const KeyCode&            aKey);
205cdf0e10cSrcweir         virtual void execute(const css::awt::KeyEvent& aKey);
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         //---------------------------------------
208cdf0e10cSrcweir         /** TODO document me */
209cdf0e10cSrcweir         static css::awt::KeyEvent st_VCLKey2AWTKey(const KeyCode&            aKey);
210cdf0e10cSrcweir         static KeyCode            st_AWTKey2VCLKey(const css::awt::KeyEvent& aKey);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     //-------------------------------------------
213cdf0e10cSrcweir     // internal
214cdf0e10cSrcweir     private:
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         //---------------------------------------
217cdf0e10cSrcweir         /** @short  allow creation of instances of this class
218cdf0e10cSrcweir                     by using our factory only!
219cdf0e10cSrcweir          */
220cdf0e10cSrcweir         AcceleratorExecute();
221cdf0e10cSrcweir         AcceleratorExecute(const AcceleratorExecute& rCopy);
222cdf0e10cSrcweir         void operator=(const AcceleratorExecute& rCopy) {};
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         //---------------------------------------
225cdf0e10cSrcweir         /** TODO document me */
226cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > impl_st_openGlobalConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > impl_st_openModuleConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
229cdf0e10cSrcweir                                                                                             const css::uno::Reference< css::frame::XFrame >&              xFrame);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         css::uno::Reference< css::ui::XAcceleratorConfiguration > impl_st_openDocConfig(const css::uno::Reference< css::frame::XModel >& xModel);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         //---------------------------------------
234cdf0e10cSrcweir         /** TODO document me */
235cdf0e10cSrcweir         ::rtl::OUString impl_ts_findCommand(const css::awt::KeyEvent& aKey);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         //---------------------------------------
238cdf0e10cSrcweir         /** TODO document me */
239cdf0e10cSrcweir         css::uno::Reference< css::util::XURLTransformer > impl_ts_getURLParser();
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         //---------------------------------------
242cdf0e10cSrcweir         /** TODO document me */
243cdf0e10cSrcweir         DECL_LINK(impl_ts_asyncCallback, void*);
244cdf0e10cSrcweir };
245cdf0e10cSrcweir 
246cdf0e10cSrcweir #undef  css
247cdf0e10cSrcweir #undef css
248cdf0e10cSrcweir 
249cdf0e10cSrcweir } // namespace svt
250cdf0e10cSrcweir 
251cdf0e10cSrcweir #endif // INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX
252