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 __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_______________________________________________
28cdf0e10cSrcweir // my own includes
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //_______________________________________________
33cdf0e10cSrcweir // interface includes
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //_______________________________________________
41cdf0e10cSrcweir // other includes
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
44cdf0e10cSrcweir #include <tools/link.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //_______________________________________________
47cdf0e10cSrcweir // namespace
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace framework{
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace css = ::com::sun::star;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //_______________________________________________
54cdf0e10cSrcweir // exported const
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //_______________________________________________
57cdf0e10cSrcweir // exported definitions
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /** @short  internal helper to bind e.g. MAC-Menu events to our internal dispatch API.
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     @descr  On e.g. MAC platform system menus are merged together with some fix entries as
62cdf0e10cSrcweir             e.g. "Pereferences" or "About". These menu entries trigger hard coded commands.
63cdf0e10cSrcweir             Here we map these commands to the right URLs and dispatch them.
64cdf0e10cSrcweir 
65cdf0e10cSrcweir             This helper knows a frame and it's container window (where VCL provide the hard coded
66cdf0e10cSrcweir             commands). We hold those objects weak ... so there is no need to react for complex dispose/ing()
67cdf0e10cSrcweir             scenarios. On the other side VCL does not hold us alive (because it doesn't know our UNO reference).
68cdf0e10cSrcweir             So we register us at the XWindow as event listener also to be sure to live as long the XWindow/VCLWindow lives.
69cdf0e10cSrcweir  */
70cdf0e10cSrcweir class WindowCommandDispatch : private ThreadHelpBase
71cdf0e10cSrcweir                   , public  ::cppu::WeakImplHelper1< css::lang::XEventListener >
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     //___________________________________________
74cdf0e10cSrcweir     // const
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     private:
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         /// dispatch URL to trigger our "Tools->Options" dialog
79cdf0e10cSrcweir         static const ::rtl::OUString COMMAND_PREFERENCES;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         /// dispatch URL to trigger our About box
82cdf0e10cSrcweir         static const ::rtl::OUString COMMAND_ABOUTBOX;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     //___________________________________________
85cdf0e10cSrcweir     // member
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     private:
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         /// can be used to create own needed services on demand.
90cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         /// knows the frame, where we dispatch our commands as weak reference
93cdf0e10cSrcweir         css::uno::WeakReference< css::frame::XFrame > m_xFrame;
94cdf0e10cSrcweir 
95*07a3d7f1SPedro Giffuni         /// knows the VCL window (where the hard coded commands occurred) as weak XWindow reference
96cdf0e10cSrcweir         css::uno::WeakReference< css::awt::XWindow > m_xWindow;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     //___________________________________________
99cdf0e10cSrcweir     // native interface
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     public:
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         //_______________________________________
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         /** @short  creates a new instance and initialize it with all necessary parameters.
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             @descr  Every instance of such MACDispatch can be used for the specified context only.
108cdf0e10cSrcweir                     Means: 1 MACDispatch object is bound to 1 Frame/Window pair in which context
109cdf0e10cSrcweir                     the detected commands will be executed.
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             @param  xSMGR
112cdf0e10cSrcweir                     will be used to create own needed services on demand.
113cdf0e10cSrcweir 
114cdf0e10cSrcweir             @param  xFrame
115cdf0e10cSrcweir                     used as for new detected commands.
116cdf0e10cSrcweir          */
117cdf0e10cSrcweir         WindowCommandDispatch(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
118cdf0e10cSrcweir                               const css::uno::Reference< css::frame::XFrame >&              xFrame);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         //_______________________________________
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         /** @short  used to free internal resources.
123cdf0e10cSrcweir          */
124cdf0e10cSrcweir         virtual ~WindowCommandDispatch();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     //___________________________________________
127cdf0e10cSrcweir     // uno interface
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     public:
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         // XEventListener
132cdf0e10cSrcweir          virtual void SAL_CALL disposing(const css::lang::EventObject& aSource)
133cdf0e10cSrcweir             throw (css::uno::RuntimeException);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     //___________________________________________
136cdf0e10cSrcweir     // implementation
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     private:
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         //_______________________________________
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         /** @short  establish all listener connections we need.
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             @descr  Those listener connections will be created one times only (see ctor).
145cdf0e10cSrcweir                     Afterwards we listen for incoming events till our referred frame/window pair
146cdf0e10cSrcweir                     will be closed. All objects die by refcount automatically. Because we hold
147cdf0e10cSrcweir                     it weak ...
148cdf0e10cSrcweir          */
149cdf0e10cSrcweir         void impl_startListening();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         //_______________________________________
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         /** @short  callback from VCL to notify new commands
154cdf0e10cSrcweir          */
155cdf0e10cSrcweir         DECL_LINK( impl_notifyCommand, void* );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         //_______________________________________
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         /** @short  dispatch right command URLs into our frame context.
160cdf0e10cSrcweir 
161cdf0e10cSrcweir             @param  sCommand
162cdf0e10cSrcweir                     the command for dispatch
163cdf0e10cSrcweir          */
164cdf0e10cSrcweir         void impl_dispatchCommand(const ::rtl::OUString& sCommand);
165cdf0e10cSrcweir 
166cdf0e10cSrcweir }; // class MACDispatch
167cdf0e10cSrcweir 
168cdf0e10cSrcweir } // namespace framework
169cdf0e10cSrcweir 
170cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_DISPATCH_MACDISPATCH_HXX_
171