Update git submodules
[LibreOffice.git] / framework / source / inc / dispatch / windowcommanddispatch.hxx
blob4a8a22d81c0b2bbd010a15dc207955a86c3e6ab0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <com/sun/star/awt/XWindow.hpp>
23 #include <com/sun/star/frame/XFrame.hpp>
25 #include <cppuhelper/weakref.hxx>
26 #include <tools/link.hxx>
27 #include <mutex>
29 namespace com::sun::star::uno {
30 class XComponentContext;
32 class VclWindowEvent;
34 namespace framework{
36 /** @short internal helper to bind e.g. MAC-Menu events to our internal dispatch API.
38 @descr On e.g. MAC platform system menus are merged together with some fix entries as
39 e.g. "Pereferences" or "About". These menu entries trigger hard coded commands.
40 Here we map these commands to the right URLs and dispatch them.
42 This helper knows a frame and its container window (where VCL provide the hard coded
43 commands). We hold those objects weak so there is no need to react for complex UNO dispose/ing()
44 scenarios. On the other side VCL does not hold us alive (because it doesn't know our UNO reference).
45 So we register at the VCL level as an event listener and
47 class WindowCommandDispatch final
49 private:
50 std::mutex m_mutex;
52 /// can be used to create own needed services on demand.
53 css::uno::Reference< css::uno::XComponentContext > m_xContext;
55 /// knows the frame, where we dispatch our commands as weak reference
56 css::uno::WeakReference< css::frame::XFrame > m_xFrame;
58 /// knows the VCL window (where the hard coded commands occurred) as weak XWindow reference
59 css::uno::WeakReference< css::awt::XWindow > m_xWindow;
61 // native interface
63 public:
65 /** @short creates a new instance and initialize it with all necessary parameters.
67 @descr Every instance of such MACDispatch can be used for the specified context only.
68 Means: 1 MACDispatch object is bound to 1 Frame/Window pair in which context
69 the detected commands will be executed.
71 @param xContext
72 will be used to create own needed services on demand.
74 @param xFrame
75 used as for new detected commands.
77 WindowCommandDispatch(css::uno::Reference< css::uno::XComponentContext > xContext ,
78 const css::uno::Reference< css::frame::XFrame >& xFrame);
80 /** @short used to free internal resources.
82 ~WindowCommandDispatch();
84 // implementation
86 private:
88 /** @short establish all listener connections we need.
90 @descr Those listener connections will be created one times only (see ctor).
91 Afterwards we listen for incoming events till our referred frame/window pair
92 will be closed.
94 void impl_startListening();
96 /** @short drop all listener connections we need.
99 void impl_stopListening();
101 /** @short callback from VCL to notify new commands
103 DECL_LINK( impl_notifyCommand, VclWindowEvent&, void );
105 }; // class WindowCommandDispatch
107 } // namespace framework
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */