1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_DISPATCH_WINDOWCOMMANDDISPATCH_HXX
21 #define INCLUDED_FRAMEWORK_SOURCE_INC_DISPATCH_WINDOWCOMMANDDISPATCH_HXX
23 #include <com/sun/star/awt/XWindow.hpp>
24 #include <com/sun/star/frame/XFrame.hpp>
25 #include <com/sun/star/lang/XEventListener.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <cppuhelper/implbase1.hxx>
29 #include <tools/link.hxx>
31 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
32 class XComponentContext
;
37 /** @short internal helper to bind e.g. MAC-Menu events to our internal dispatch API.
39 @descr On e.g. MAC platform system menus are merged together with some fix entries as
40 e.g. "Pereferences" or "About". These menu entries trigger hard coded commands.
41 Here we map these commands to the right URLs and dispatch them.
43 This helper knows a frame and its container window (where VCL provide the hard coded
44 commands). We hold those objects weak so there is no need to react for complex UNO dispose/ing()
45 scenarios. On the other side VCL does not hold us alive (because it doesn't know our UNO reference).
46 So we register at the VCL level as an event listener and
48 class WindowCommandDispatch
53 /// can be used to create own needed services on demand.
54 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
56 /// knows the frame, where we dispatch our commands as weak reference
57 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
59 /// knows the VCL window (where the hard coded commands occurred) as weak XWindow reference
60 css::uno::WeakReference
< css::awt::XWindow
> m_xWindow
;
66 /** @short creates a new instance and initialize it with all necessary parameters.
68 @descr Every instance of such MACDispatch can be used for the specified context only.
69 Means: 1 MACDispatch object is bound to 1 Frame/Window pair in which context
70 the detected commands will be executed.
73 will be used to create own needed services on demand.
76 used as for new detected commands.
78 WindowCommandDispatch(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
79 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
81 /** @short used to free internal resources.
83 virtual ~WindowCommandDispatch();
89 /** @short establish all listener connections we need.
91 @descr Those listener connections will be created one times only (see ctor).
92 Afterwards we listen for incoming events till our referred frame/window pair
95 void impl_startListening();
97 /** @short drop all listener connections we need.
100 void impl_stopListening();
102 /** @short callback from VCL to notify new commands
104 DECL_LINK( impl_notifyCommand
, void* );
106 /** @short dispatch right command URLs into our frame context.
109 the command for dispatch
111 void impl_dispatchCommand(const OUString
& sCommand
);
113 }; // class MACDispatch
115 } // namespace framework
117 #endif // INCLUDED_FRAMEWORK_SOURCE_INC_DISPATCH_WINDOWCOMMANDDISPATCH_HXX
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */