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