fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / dispatch / startmoduledispatcher.cxx
blob726802cbb05048e58465ec45d9b277eaa0191dd4
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 #include <dispatch/startmoduledispatcher.hxx>
22 #include <pattern/frame.hxx>
23 #include <framework/framelistanalyzer.hxx>
24 #include <dispatchcommands.h>
25 #include <targets.h>
26 #include <services.h>
27 #include <general.h>
29 #include <com/sun/star/frame/Desktop.hpp>
30 #include <com/sun/star/frame/XController.hpp>
31 #include <com/sun/star/frame/CommandGroup.hpp>
32 #include <com/sun/star/frame/StartModule.hpp>
33 #include <com/sun/star/awt/XTopWindow.hpp>
34 #include <com/sun/star/beans/XFastPropertySet.hpp>
35 #include <com/sun/star/frame/XModuleManager.hpp>
37 #include <toolkit/helper/vclunohelper.hxx>
38 #include <vcl/window.hxx>
39 #include <vcl/svapp.hxx>
40 #include <osl/mutex.hxx>
41 #include <unotools/moduleoptions.hxx>
42 #include <comphelper/processfactory.hxx>
44 namespace framework{
46 #ifdef fpf
47 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
48 #endif
49 namespace fpf = ::framework::pattern::frame;
51 StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
52 const css::uno::Reference< css::frame::XFrame >& xFrame)
53 : m_xContext (rxContext )
54 , m_xOwner (xFrame )
55 , m_lStatusListener (m_mutex)
59 StartModuleDispatcher::~StartModuleDispatcher()
63 void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL& aURL ,
64 const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
65 throw(css::uno::RuntimeException, std::exception)
67 dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
70 void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
71 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
72 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
73 throw(css::uno::RuntimeException, std::exception)
75 ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
76 if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
78 nResult = css::frame::DispatchResultState::FAILURE;
79 if (implts_isBackingModePossible ())
81 if (implts_establishBackingMode ())
82 nResult = css::frame::DispatchResultState::SUCCESS;
86 implts_notifyResultListener(xListener, nResult, css::uno::Any());
89 css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
90 throw(css::uno::RuntimeException, std::exception)
92 return css::uno::Sequence< ::sal_Int16 >();
95 css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
96 throw(css::uno::RuntimeException, std::exception)
98 return css::uno::Sequence< css::frame::DispatchInformation >();
101 void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
102 const css::util::URL& /*aURL*/ )
103 throw(css::uno::RuntimeException, std::exception)
107 void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
108 const css::util::URL& /*aURL*/ )
109 throw(css::uno::RuntimeException, std::exception)
113 bool StartModuleDispatcher::implts_isBackingModePossible()
115 if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE))
116 return false;
118 css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
119 css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY);
121 FrameListAnalyzer aCheck(
122 xDesktop,
123 css::uno::Reference< css::frame::XFrame >(),
124 FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
126 bool bIsPossible = false;
127 ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
129 if (
130 ( ! aCheck.m_xBackingComponent.is ()) &&
131 ( nVisibleFrames < 1 )
134 bIsPossible = true;
137 return bIsPossible;
140 bool StartModuleDispatcher::implts_establishBackingMode()
142 css::uno::Reference< css::frame::XDesktop2> xDesktop = css::frame::Desktop::create( m_xContext );
143 css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->findFrame(SPECIALTARGET_BLANK, 0);
144 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
146 css::uno::Reference< css::frame::XController > xStartModule = css::frame::StartModule::createWithParentWindow(m_xContext, xContainerWindow);
147 css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
148 xFrame->setComponent(xComponentWindow, xStartModule);
149 xStartModule->attachFrame(xFrame);
150 xContainerWindow->setVisible(sal_True);
152 return true;
155 void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
156 ::sal_Int16 nState ,
157 const css::uno::Any& aResult )
159 if ( ! xListener.is())
160 return;
162 css::frame::DispatchResultEvent aEvent(
163 css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
164 nState,
165 aResult);
167 xListener->dispatchFinished(aEvent);
170 } // namespace framework
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */