LibreOffice Module framework (master) 1
startmoduledispatcher.cxx
Go to the documentation of this file.
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
21
23#include <targets.h>
25
26#include <com/sun/star/frame/Desktop.hpp>
27#include <com/sun/star/frame/DispatchResultState.hpp>
28#include <com/sun/star/frame/XController.hpp>
29#include <com/sun/star/frame/StartModule.hpp>
30
32#include <utility>
33
34namespace framework{
35
36#ifdef fpf
37 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
38#endif
39
40StartModuleDispatcher::StartModuleDispatcher(css::uno::Reference< css::uno::XComponentContext > xContext)
41 : m_xContext (std::move(xContext ))
42{
43}
44
46{
47}
48
49void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL& aURL ,
50 const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
51{
52 dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
53}
54
55void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
56 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
57 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
58{
59 ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
61 {
62 nResult = css::frame::DispatchResultState::FAILURE;
64 {
66 nResult = css::frame::DispatchResultState::SUCCESS;
67 }
68 }
69
70 implts_notifyResultListener(xListener, nResult, css::uno::Any());
71}
72
73css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
74{
75 return css::uno::Sequence< ::sal_Int16 >();
76}
77
78css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
79{
80 return css::uno::Sequence< css::frame::DispatchInformation >();
81}
82
83void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
84 const css::util::URL& /*aURL*/ )
85{
86}
87
88void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
89 const css::util::URL& /*aURL*/ )
90{
91}
92
94{
96 return false;
97
98 css::uno::Reference< css::frame::XFramesSupplier > xDesktop =
99 css::frame::Desktop::create( m_xContext );
100
101 FrameListAnalyzer aCheck(
102 xDesktop,
103 css::uno::Reference< css::frame::XFrame >(),
105
106 bool bIsPossible = false;
107
108 if ( ! aCheck.m_xBackingComponent.is()
109 && aCheck.m_lOtherVisibleFrames.empty() )
110 {
111 bIsPossible = true;
112 }
113
114 return bIsPossible;
115}
116
118{
119 css::uno::Reference< css::frame::XDesktop2> xDesktop = css::frame::Desktop::create( m_xContext );
120 css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->findFrame(SPECIALTARGET_BLANK, 0);
121 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
122
123 css::uno::Reference< css::frame::XController > xStartModule = css::frame::StartModule::createWithParentWindow(m_xContext, xContainerWindow);
124 css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
125 xFrame->setComponent(xComponentWindow, xStartModule);
126 xStartModule->attachFrame(xFrame);
127 xContainerWindow->setVisible(true);
128}
129
130void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
131 ::sal_Int16 nState ,
132 const css::uno::Any& aResult )
133{
134 if ( ! xListener.is())
135 return;
136
137 css::frame::DispatchResultEvent aEvent(
138 css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
139 nState,
140 aResult);
141
142 xListener->dispatchFinished(aEvent);
143}
144
145} // namespace framework
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
StartModuleDispatcher(css::uno::Reference< css::uno::XComponentContext > xContext)
connect a new StartModuleDispatcher instance to its "owner frame".
virtual ~StartModuleDispatcher() override
does nothing real.
bool implts_isBackingModePossible()
check if StartModule can be shown.
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation(sal_Int16 nCommandGroup) override
virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups() override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
reference to a uno service manager, which can be used to create own needed uno resources.
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
void implts_establishBackingMode()
open the special BackingComponent (now StartModule)
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Reference< css::frame::XDispatchResultListener > &xListener) override
void implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener > &xListener, sal_Int16 nState, const css::uno::Any &aResult)
notify a DispatchResultListener.
URL aURL
sal_Int32 nState
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr OUStringLiteral SPECIALTARGET_BLANK
Definition: targets.h:31
bool isStartModuleDispatch(css::util::URL const &url)
Reference< XFrame > xFrame