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