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 #include <dispatch/startmoduledispatcher.hxx>
22 #include <framework/framelistanalyzer.hxx>
24 #include "isstartmoduledispatch.hxx"
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>
31 #include <unotools/moduleoptions.hxx>
37 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
40 StartModuleDispatcher::StartModuleDispatcher(css::uno::Reference
< css::uno::XComponentContext
> xContext
)
41 : m_xContext (std::move(xContext
))
45 StartModuleDispatcher::~StartModuleDispatcher()
49 void SAL_CALL
StartModuleDispatcher::dispatch(const css::util::URL
& aURL
,
50 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
)
52 dispatchWithNotification(aURL
, lArguments
, css::uno::Reference
< css::frame::XDispatchResultListener
>());
55 void 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
)
59 ::sal_Int16 nResult
= css::frame::DispatchResultState::DONTKNOW
;
60 if (isStartModuleDispatch(aURL
))
62 nResult
= css::frame::DispatchResultState::FAILURE
;
63 if (implts_isBackingModePossible ())
65 implts_establishBackingMode ();
66 nResult
= css::frame::DispatchResultState::SUCCESS
;
70 implts_notifyResultListener(xListener
, nResult
, css::uno::Any());
73 css::uno::Sequence
< ::sal_Int16
> SAL_CALL
StartModuleDispatcher::getSupportedCommandGroups()
75 return css::uno::Sequence
< ::sal_Int16
>();
78 css::uno::Sequence
< css::frame::DispatchInformation
> SAL_CALL
StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16
/*nCommandGroup*/)
80 return css::uno::Sequence
< css::frame::DispatchInformation
>();
83 void SAL_CALL
StartModuleDispatcher::addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
84 const css::util::URL
& /*aURL*/ )
88 void SAL_CALL
StartModuleDispatcher::removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
89 const css::util::URL
& /*aURL*/ )
93 bool StartModuleDispatcher::implts_isBackingModePossible()
95 if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE
))
98 css::uno::Reference
< css::frame::XFramesSupplier
> xDesktop
=
99 css::frame::Desktop::create( m_xContext
);
101 FrameListAnalyzer
aCheck(
103 css::uno::Reference
< css::frame::XFrame
>(),
104 FrameAnalyzerFlags::Help
| FrameAnalyzerFlags::BackingComponent
);
106 bool bIsPossible
= false;
108 if ( ! aCheck
.m_xBackingComponent
.is()
109 && aCheck
.m_lOtherVisibleFrames
.empty() )
117 void StartModuleDispatcher::implts_establishBackingMode()
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();
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);
130 void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
,
132 const css::uno::Any
& aResult
)
134 if ( ! xListener
.is())
137 css::frame::DispatchResultEvent
aEvent(
138 css::uno::Reference
< css::uno::XInterface
>(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
),
142 xListener
->dispatchFinished(aEvent
);
145 } // namespace framework
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */