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