1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <dispatch/startmoduledispatcher.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir //_______________________________________________ 30cdf0e10cSrcweir // my own includes 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <pattern/frame.hxx> 33cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 34cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 35cdf0e10cSrcweir #include <framework/framelistanalyzer.hxx> 36cdf0e10cSrcweir #include <dispatchcommands.h> 37cdf0e10cSrcweir #include <targets.h> 38cdf0e10cSrcweir #include <services.h> 39cdf0e10cSrcweir #include <general.h> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //_______________________________________________ 42cdf0e10cSrcweir // interface includes 43cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 44cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 45cdf0e10cSrcweir #include <com/sun/star/frame/CommandGroup.hpp> 46cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp> 47cdf0e10cSrcweir #include "com/sun/star/beans/XFastPropertySet.hpp" 48cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 49cdf0e10cSrcweir 50cdf0e10cSrcweir //_______________________________________________ 51cdf0e10cSrcweir // includes of other projects 52cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 53cdf0e10cSrcweir #include <vcl/window.hxx> 54cdf0e10cSrcweir #include <vcl/svapp.hxx> 55cdf0e10cSrcweir #include <vos/mutex.hxx> 56cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 57cdf0e10cSrcweir 58cdf0e10cSrcweir //_______________________________________________ 59cdf0e10cSrcweir // namespace 60cdf0e10cSrcweir 61cdf0e10cSrcweir namespace framework{ 62cdf0e10cSrcweir 63cdf0e10cSrcweir #ifdef fpf 64cdf0e10cSrcweir #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..." 65cdf0e10cSrcweir #endif 66cdf0e10cSrcweir namespace fpf = ::framework::pattern::frame; 67cdf0e10cSrcweir 68cdf0e10cSrcweir //_______________________________________________ 69cdf0e10cSrcweir // declarations 70cdf0e10cSrcweir 71cdf0e10cSrcweir DEFINE_XINTERFACE_4(StartModuleDispatcher , 72cdf0e10cSrcweir OWeakObject , 73cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ), 74cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XNotifyingDispatch ), 75cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatch ), 76cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatchInformationProvider)) 77cdf0e10cSrcweir 78cdf0e10cSrcweir // Note: XStatusListener is an implementation detail. Hide it for scripting! 79cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher , 80cdf0e10cSrcweir css::lang::XTypeProvider , 81cdf0e10cSrcweir css::frame::XDispatchInformationProvider, 82cdf0e10cSrcweir css::frame::XNotifyingDispatch , 83cdf0e10cSrcweir css::frame::XDispatch ) 84cdf0e10cSrcweir 85cdf0e10cSrcweir //----------------------------------------------- 86cdf0e10cSrcweir StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 87cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xFrame , 88cdf0e10cSrcweir const ::rtl::OUString& sTarget) 89cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex() ) 90cdf0e10cSrcweir , ::cppu::OWeakObject( ) 91cdf0e10cSrcweir , m_xSMGR (xSMGR ) 92cdf0e10cSrcweir , m_xOwner (xFrame ) 93cdf0e10cSrcweir , m_sDispatchTarget (sTarget ) 94cdf0e10cSrcweir , m_lStatusListener (m_aLock.getShareableOslMutex()) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir //----------------------------------------------- 99cdf0e10cSrcweir StartModuleDispatcher::~StartModuleDispatcher() 100cdf0e10cSrcweir { 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir //----------------------------------------------- 104cdf0e10cSrcweir void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL& aURL , 105cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments) 106cdf0e10cSrcweir throw(css::uno::RuntimeException) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >()); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir //----------------------------------------------- 112cdf0e10cSrcweir void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL& aURL , 113cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/, 114cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) 115cdf0e10cSrcweir throw(css::uno::RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW; 118cdf0e10cSrcweir if (aURL.Complete.equals (CMD_UNO_SHOWSTARTMODULE)) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir nResult = css::frame::DispatchResultState::FAILURE; 121cdf0e10cSrcweir if (implts_isBackingModePossible ()) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir if (implts_establishBackingMode ()) 124cdf0e10cSrcweir nResult = css::frame::DispatchResultState::SUCCESS; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir implts_notifyResultListener(xListener, nResult, css::uno::Any()); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir //----------------------------------------------- 132cdf0e10cSrcweir css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups() 133cdf0e10cSrcweir throw(css::uno::RuntimeException) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir return css::uno::Sequence< ::sal_Int16 >(); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir //----------------------------------------------- 139cdf0e10cSrcweir css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/) 140cdf0e10cSrcweir throw(css::uno::RuntimeException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir return css::uno::Sequence< css::frame::DispatchInformation >(); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir //----------------------------------------------- 146cdf0e10cSrcweir void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/, 147cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) 148cdf0e10cSrcweir throw(css::uno::RuntimeException) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir //----------------------------------------------- 153cdf0e10cSrcweir void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/, 154cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) 155cdf0e10cSrcweir throw(css::uno::RuntimeException) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //----------------------------------------------- 160cdf0e10cSrcweir ::sal_Bool StartModuleDispatcher::implts_isBackingModePossible () 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE)) 163cdf0e10cSrcweir return sal_False; 164cdf0e10cSrcweir 165cdf0e10cSrcweir // SAFE -> ---------------------------------- 166cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 167cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 168cdf0e10cSrcweir aReadLock.unlock(); 169cdf0e10cSrcweir // <- SAFE ---------------------------------- 170cdf0e10cSrcweir 171cdf0e10cSrcweir css::uno::Reference< css::frame::XFramesSupplier > xDesktop( 172cdf0e10cSrcweir xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY); 173cdf0e10cSrcweir 174cdf0e10cSrcweir FrameListAnalyzer aCheck( 175cdf0e10cSrcweir xDesktop, 176cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(), 177cdf0e10cSrcweir FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT); 178cdf0e10cSrcweir 179cdf0e10cSrcweir ::sal_Bool bIsPossible = sal_False; 180cdf0e10cSrcweir ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength (); 181cdf0e10cSrcweir 182cdf0e10cSrcweir if ( 183cdf0e10cSrcweir ( ! aCheck.m_xBackingComponent.is ()) && 184cdf0e10cSrcweir ( nVisibleFrames < 1 ) 185cdf0e10cSrcweir ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir bIsPossible = sal_True; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir return bIsPossible; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir //----------------------------------------------- 194cdf0e10cSrcweir ::sal_Bool StartModuleDispatcher::implts_establishBackingMode() 195cdf0e10cSrcweir { 196cdf0e10cSrcweir // SAFE -> ---------------------------------- 197cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 198cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 199cdf0e10cSrcweir aReadLock.unlock(); 200cdf0e10cSrcweir // <- SAFE ---------------------------------- 201cdf0e10cSrcweir 202cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xDesktop (xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY); 203cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->findFrame (SPECIALTARGET_BLANK, 0); 204cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow (); 205cdf0e10cSrcweir 206cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lArgs(1); 207cdf0e10cSrcweir lArgs[0] <<= xContainerWindow; 208cdf0e10cSrcweir 209cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xStartModule( 210cdf0e10cSrcweir xSMGR->createInstanceWithArguments(SERVICENAME_STARTMODULE, lArgs), 211cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 212cdf0e10cSrcweir 213cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY); 214cdf0e10cSrcweir xFrame->setComponent(xComponentWindow, xStartModule); 215cdf0e10cSrcweir xStartModule->attachFrame(xFrame); 216cdf0e10cSrcweir xContainerWindow->setVisible(sal_True); 217cdf0e10cSrcweir 218cdf0e10cSrcweir return sal_True; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir //----------------------------------------------- 222cdf0e10cSrcweir void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener, 223cdf0e10cSrcweir ::sal_Int16 nState , 224cdf0e10cSrcweir const css::uno::Any& aResult ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir if ( ! xListener.is()) 227cdf0e10cSrcweir return; 228cdf0e10cSrcweir 229cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent( 230cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), 231cdf0e10cSrcweir nState, 232cdf0e10cSrcweir aResult); 233cdf0e10cSrcweir 234cdf0e10cSrcweir xListener->dispatchFinished(aEvent); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir } // namespace framework 238