/src/libreoffice/comphelper/source/misc/dispatchcommand.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <comphelper/dispatchcommand.hxx> |
21 | | #include <comphelper/processfactory.hxx> |
22 | | |
23 | | #include <com/sun/star/frame/Desktop.hpp> |
24 | | #include <com/sun/star/frame/XDispatch.hpp> |
25 | | #include <com/sun/star/frame/XDispatchProvider.hpp> |
26 | | #include <com/sun/star/frame/XNotifyingDispatch.hpp> |
27 | | #include <com/sun/star/util/URL.hpp> |
28 | | #include <com/sun/star/util/URLTransformer.hpp> |
29 | | |
30 | | using namespace css; |
31 | | |
32 | | namespace comphelper { |
33 | | |
34 | | bool dispatchCommand(const OUString& rCommand, |
35 | | const uno::Reference<frame::XDispatchProvider>& xDispatchProvider, |
36 | | const uno::Sequence<beans::PropertyValue>& rArguments, |
37 | | const uno::Reference<frame::XDispatchResultListener>& xListener) |
38 | 0 | { |
39 | 0 | if (!xDispatchProvider.is()) |
40 | 0 | return false; |
41 | | |
42 | 0 | util::URL aCommandURL; |
43 | 0 | aCommandURL.Complete = rCommand; |
44 | 0 | const uno::Reference<uno::XComponentContext>& xContext = ::comphelper::getProcessComponentContext(); |
45 | 0 | uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext); |
46 | 0 | xParser->parseStrict(aCommandURL); |
47 | |
|
48 | 0 | uno::Reference<frame::XDispatch> xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0); |
49 | 0 | if (!xDisp.is()) |
50 | 0 | return false; |
51 | | |
52 | | // And do the work... |
53 | 0 | if (xListener.is()) |
54 | 0 | { |
55 | 0 | uno::Reference<frame::XNotifyingDispatch> xNotifyingDisp(xDisp, uno::UNO_QUERY); |
56 | 0 | if (xNotifyingDisp.is()) |
57 | 0 | { |
58 | 0 | xNotifyingDisp->dispatchWithNotification(aCommandURL, rArguments, xListener); |
59 | 0 | return true; |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | 0 | xDisp->dispatch(aCommandURL, rArguments); |
64 | |
|
65 | 0 | return true; |
66 | 0 | } |
67 | | |
68 | | bool dispatchCommand(const OUString& rCommand, |
69 | | const uno::Reference<frame::XFrame>& xFrame, |
70 | | const uno::Sequence<beans::PropertyValue>& rArguments, |
71 | | const uno::Reference<frame::XDispatchResultListener>& xListener) |
72 | 0 | { |
73 | 0 | return dispatchCommand(rCommand, xFrame.query<frame::XDispatchProvider>(), rArguments, xListener); |
74 | 0 | } |
75 | | |
76 | | bool dispatchCommand(const OUString& rCommand, |
77 | | const uno::Reference<frame::XController>& xController, |
78 | | const uno::Sequence<beans::PropertyValue>& rArguments, |
79 | | const uno::Reference<frame::XDispatchResultListener>& xListener) |
80 | 0 | { |
81 | 0 | return dispatchCommand(rCommand, xController.query<frame::XDispatchProvider>(), rArguments, xListener); |
82 | 0 | } |
83 | | |
84 | | bool dispatchCommand(const OUString& rCommand, |
85 | | const uno::Sequence<beans::PropertyValue>& rArguments, |
86 | | const uno::Reference<frame::XDispatchResultListener>& xListener) |
87 | 0 | { |
88 | | // Target where we will execute the .uno: command |
89 | 0 | const uno::Reference<uno::XComponentContext>& xContext = ::comphelper::getProcessComponentContext(); |
90 | 0 | uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext); |
91 | |
|
92 | 0 | uno::Reference<frame::XFrame> xFrame(xDesktop->getActiveFrame()); |
93 | 0 | if (!xFrame.is()) |
94 | 0 | xFrame = xDesktop; |
95 | |
|
96 | 0 | return dispatchCommand(rCommand, xFrame, rArguments, xListener); |
97 | 0 | } |
98 | | |
99 | | } // namespace comphelper |
100 | | |
101 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |