bump product version to 4.1.6.2
[LibreOffice.git] / framework / source / dispatch / startmoduledispatcher.cxx
blob56f87f8d498c487f8f0b4ce49a6fe48f0591e8ec
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 .
21 #include <dispatch/startmoduledispatcher.hxx>
23 #include <pattern/frame.hxx>
24 #include <threadhelp/readguard.hxx>
25 #include <threadhelp/writeguard.hxx>
26 #include <framework/framelistanalyzer.hxx>
27 #include <dispatchcommands.h>
28 #include <targets.h>
29 #include <services.h>
30 #include <general.h>
32 #include <com/sun/star/frame/Desktop.hpp>
33 #include <com/sun/star/frame/XController.hpp>
34 #include <com/sun/star/frame/CommandGroup.hpp>
35 #include <com/sun/star/frame/StartModule.hpp>
36 #include <com/sun/star/awt/XTopWindow.hpp>
37 #include "com/sun/star/beans/XFastPropertySet.hpp"
38 #include <com/sun/star/frame/XModuleManager.hpp>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <vcl/window.hxx>
42 #include <vcl/svapp.hxx>
43 #include <osl/mutex.hxx>
44 #include <unotools/moduleoptions.hxx>
45 #include <comphelper/processfactory.hxx>
48 namespace framework{
50 #ifdef fpf
51 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
52 #endif
53 namespace fpf = ::framework::pattern::frame;
56 DEFINE_XINTERFACE_4(StartModuleDispatcher ,
57 OWeakObject ,
58 DIRECT_INTERFACE(css::lang::XTypeProvider ),
59 DIRECT_INTERFACE(css::frame::XNotifyingDispatch ),
60 DIRECT_INTERFACE(css::frame::XDispatch ),
61 DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
63 // Note: XStatusListener is an implementation detail. Hide it for scripting!
64 DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher ,
65 css::lang::XTypeProvider ,
66 css::frame::XDispatchInformationProvider,
67 css::frame::XNotifyingDispatch ,
68 css::frame::XDispatch )
70 //-----------------------------------------------
71 StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
72 const css::uno::Reference< css::frame::XFrame >& xFrame ,
73 const OUString& sTarget)
74 : ThreadHelpBase (&Application::GetSolarMutex() )
75 , ::cppu::OWeakObject( )
76 , m_xContext (rxContext )
77 , m_xOwner (xFrame )
78 , m_sDispatchTarget (sTarget )
79 , m_lStatusListener (m_aLock.getShareableOslMutex())
83 //-----------------------------------------------
84 StartModuleDispatcher::~StartModuleDispatcher()
88 //-----------------------------------------------
89 void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL& aURL ,
90 const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
91 throw(css::uno::RuntimeException)
93 dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
96 //-----------------------------------------------
97 void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
98 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
99 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
100 throw(css::uno::RuntimeException)
102 ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
103 if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
105 nResult = css::frame::DispatchResultState::FAILURE;
106 if (implts_isBackingModePossible ())
108 if (implts_establishBackingMode ())
109 nResult = css::frame::DispatchResultState::SUCCESS;
113 implts_notifyResultListener(xListener, nResult, css::uno::Any());
116 //-----------------------------------------------
117 css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
118 throw(css::uno::RuntimeException)
120 return css::uno::Sequence< ::sal_Int16 >();
123 //-----------------------------------------------
124 css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
125 throw(css::uno::RuntimeException)
127 return css::uno::Sequence< css::frame::DispatchInformation >();
130 //-----------------------------------------------
131 void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
132 const css::util::URL& /*aURL*/ )
133 throw(css::uno::RuntimeException)
137 //-----------------------------------------------
138 void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
139 const css::util::URL& /*aURL*/ )
140 throw(css::uno::RuntimeException)
144 //-----------------------------------------------
145 ::sal_Bool StartModuleDispatcher::implts_isBackingModePossible ()
147 if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE))
148 return sal_False;
150 // SAFE -> ----------------------------------
151 ReadGuard aReadLock(m_aLock);
152 css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
153 aReadLock.unlock();
154 // <- SAFE ----------------------------------
156 css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
157 css::frame::Desktop::create( xContext ), css::uno::UNO_QUERY);
159 FrameListAnalyzer aCheck(
160 xDesktop,
161 css::uno::Reference< css::frame::XFrame >(),
162 FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
164 ::sal_Bool bIsPossible = sal_False;
165 ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
167 if (
168 ( ! aCheck.m_xBackingComponent.is ()) &&
169 ( nVisibleFrames < 1 )
172 bIsPossible = sal_True;
175 return bIsPossible;
178 //-----------------------------------------------
179 ::sal_Bool StartModuleDispatcher::implts_establishBackingMode()
181 // SAFE -> ----------------------------------
182 ReadGuard aReadLock(m_aLock);
183 css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
184 aReadLock.unlock();
185 // <- SAFE ----------------------------------
187 css::uno::Reference< css::frame::XDesktop2> xDesktop = css::frame::Desktop::create( xContext );
188 css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->findFrame(SPECIALTARGET_BLANK, 0);
189 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
191 css::uno::Reference< css::frame::XController > xStartModule = css::frame::StartModule::createWithParentWindow(xContext, xContainerWindow);
192 css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
193 xFrame->setComponent(xComponentWindow, xStartModule);
194 xStartModule->attachFrame(xFrame);
195 xContainerWindow->setVisible(sal_True);
197 return sal_True;
200 //-----------------------------------------------
201 void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
202 ::sal_Int16 nState ,
203 const css::uno::Any& aResult )
205 if ( ! xListener.is())
206 return;
208 css::frame::DispatchResultEvent aEvent(
209 css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
210 nState,
211 aResult);
213 xListener->dispatchFinished(aEvent);
216 } // namespace framework
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */