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 10*6d739b60SAndrew Rist * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6d739b60SAndrew Rist * 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. 19*6d739b60SAndrew Rist * 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 // includes of own project 28cdf0e10cSrcweir #include <loadenv/loadenv.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #ifndef __FRAMEWORK_LOADENV_TARGETHELPER_HXX_ 31cdf0e10cSrcweir #include <loadenv/targethelper.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #include <framework/framelistanalyzer.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_FRAMELOADER_HXX_ 36cdf0e10cSrcweir #include <constant/frameloader.hxx> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir 39cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_CONTENTHANDLER_HXX_ 40cdf0e10cSrcweir #include <constant/contenthandler.hxx> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir 43cdf0e10cSrcweir #ifndef __FRAMEWORK_CONSTANT_CONTAINERQUERY_HXX_ 44cdf0e10cSrcweir #include <constant/containerquery.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #include <interaction/quietinteraction.hxx> 47cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 48cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 49cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 50cdf0e10cSrcweir #include <properties.h> 51cdf0e10cSrcweir #include <protocols.h> 52cdf0e10cSrcweir #include <services.h> 53cdf0e10cSrcweir #include <comphelper/interaction.hxx> 54cdf0e10cSrcweir #include <framework/interaction.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir //_______________________________________________ 57cdf0e10cSrcweir // includes of uno interface 58cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 59cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 60cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp> 61cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 62cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 63cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderManager.hpp> 64cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 65cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 66cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 67cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 68cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 69cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 70cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp> 71cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 72cdf0e10cSrcweir #include <com/sun/star/frame/XFrameLoader.hpp> 73cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp> 74cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp> 75cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp> 76cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp> 77cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 78cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 79cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 80cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp> 81cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 82cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 83cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 84cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp> 85cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 86cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 87cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp> 88cdf0e10cSrcweir 89cdf0e10cSrcweir //_______________________________________________ 90cdf0e10cSrcweir // includes of an other project 91cdf0e10cSrcweir #include <vcl/window.hxx> 92cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 93cdf0e10cSrcweir #include <vcl/syswin.hxx> 94cdf0e10cSrcweir 95cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 96cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 97cdf0e10cSrcweir #endif 98cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 99cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 100cdf0e10cSrcweir #include <unotools/processfactory.hxx> 101cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 102cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 103cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 104cdf0e10cSrcweir #include <vcl/svapp.hxx> 105cdf0e10cSrcweir 106cdf0e10cSrcweir //_______________________________________________ 107cdf0e10cSrcweir // namespace 108cdf0e10cSrcweir 109cdf0e10cSrcweir namespace framework{ 110cdf0e10cSrcweir 111cdf0e10cSrcweir // may there exist already a define .-( 112cdf0e10cSrcweir #ifndef css 113cdf0e10cSrcweir namespace css = ::com::sun::star; 114cdf0e10cSrcweir #endif 115cdf0e10cSrcweir 116cdf0e10cSrcweir //_______________________________________________ 117cdf0e10cSrcweir // declarations 118cdf0e10cSrcweir 119cdf0e10cSrcweir class LoadEnvListener : private ThreadHelpBase 120cdf0e10cSrcweir , public ::cppu::WeakImplHelper2< css::frame::XLoadEventListener , 121cdf0e10cSrcweir css::frame::XDispatchResultListener > 122cdf0e10cSrcweir { 123cdf0e10cSrcweir private: 124cdf0e10cSrcweir 125cdf0e10cSrcweir void** m_ppCheck ; 126cdf0e10cSrcweir LoadEnv* m_pLoadEnv; 127cdf0e10cSrcweir 128cdf0e10cSrcweir public: 129cdf0e10cSrcweir 130cdf0e10cSrcweir //_______________________________________ 131cdf0e10cSrcweir LoadEnvListener(void* pCheck , 132cdf0e10cSrcweir LoadEnv* pLoadEnv) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir m_ppCheck = &pCheck ; 135cdf0e10cSrcweir m_pLoadEnv = pLoadEnv; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir //_______________________________________ 139cdf0e10cSrcweir // frame.XLoadEventListener 140cdf0e10cSrcweir virtual void SAL_CALL loadFinished(const css::uno::Reference< css::frame::XFrameLoader >& xLoader) 141cdf0e10cSrcweir throw(css::uno::RuntimeException); 142cdf0e10cSrcweir 143cdf0e10cSrcweir virtual void SAL_CALL loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >& xLoader) 144cdf0e10cSrcweir throw(css::uno::RuntimeException); 145cdf0e10cSrcweir 146cdf0e10cSrcweir //_______________________________________ 147cdf0e10cSrcweir // frame.XDispatchResultListener 148cdf0e10cSrcweir virtual void SAL_CALL dispatchFinished(const css::frame::DispatchResultEvent& aEvent) 149cdf0e10cSrcweir throw(css::uno::RuntimeException); 150cdf0e10cSrcweir 151cdf0e10cSrcweir //_______________________________________ 152cdf0e10cSrcweir // lang.XEventListener 153cdf0e10cSrcweir virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 154cdf0e10cSrcweir throw(css::uno::RuntimeException); 155cdf0e10cSrcweir }; 156cdf0e10cSrcweir 157cdf0e10cSrcweir /*----------------------------------------------- 158cdf0e10cSrcweir 14.10.2003 13:43 159cdf0e10cSrcweir -----------------------------------------------*/ 160cdf0e10cSrcweir LoadEnv::LoadEnv(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) 161cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 162cdf0e10cSrcweir : ThreadHelpBase( ) 163cdf0e10cSrcweir , m_xSMGR (xSMGR) 164cdf0e10cSrcweir , m_pCheck (this ) 165cdf0e10cSrcweir , m_pQuietInteraction( 0 ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir /*----------------------------------------------- 170cdf0e10cSrcweir 14.10.2003 13:43 171cdf0e10cSrcweir -----------------------------------------------*/ 172cdf0e10cSrcweir LoadEnv::~LoadEnv() 173cdf0e10cSrcweir { 174cdf0e10cSrcweir m_pCheck = 0; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir /*----------------------------------------------- 178cdf0e10cSrcweir 10.09.2003 14:05 179cdf0e10cSrcweir -----------------------------------------------*/ 180cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > LoadEnv::loadComponentFromURL(const css::uno::Reference< css::frame::XComponentLoader >& xLoader, 181cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 182cdf0e10cSrcweir const ::rtl::OUString& sURL , 183cdf0e10cSrcweir const ::rtl::OUString& sTarget, 184cdf0e10cSrcweir sal_Int32 nFlags , 185cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) 186cdf0e10cSrcweir throw(css::lang::IllegalArgumentException, 187cdf0e10cSrcweir css::io::IOException , 188cdf0e10cSrcweir css::uno::RuntimeException ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xComponent; 191cdf0e10cSrcweir 192cdf0e10cSrcweir try 193cdf0e10cSrcweir { 194cdf0e10cSrcweir LoadEnv aEnv(xSMGR); 195cdf0e10cSrcweir 196cdf0e10cSrcweir aEnv.initializeLoading(sURL, 197cdf0e10cSrcweir lArgs, 198cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(xLoader, css::uno::UNO_QUERY), 199cdf0e10cSrcweir sTarget, 200cdf0e10cSrcweir nFlags, 201cdf0e10cSrcweir LoadEnv::E_NO_FEATURE); 202cdf0e10cSrcweir aEnv.startLoading(); 203cdf0e10cSrcweir aEnv.waitWhileLoading(); // wait for ever! 204cdf0e10cSrcweir 205cdf0e10cSrcweir xComponent = aEnv.getTargetComponent(); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir catch(const LoadEnvException& ex) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir switch(ex.m_nID) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir case LoadEnvException::ID_INVALID_MEDIADESCRIPTOR: 212cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 213cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Optional list of arguments seem to be corrupted."), 214cdf0e10cSrcweir xLoader, 215cdf0e10cSrcweir 4); 216cdf0e10cSrcweir 217cdf0e10cSrcweir case LoadEnvException::ID_UNSUPPORTED_CONTENT: 218cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 219cdf0e10cSrcweir ::rtl::OUString::createFromAscii("URL seems to be an unsupported one."), 220cdf0e10cSrcweir xLoader, 221cdf0e10cSrcweir 1); 222cdf0e10cSrcweir 223cdf0e10cSrcweir default: xComponent.clear(); 224cdf0e10cSrcweir break; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir return xComponent; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir //----------------------------------------------- 232cdf0e10cSrcweir ::comphelper::MediaDescriptor impl_mergeMediaDescriptorWithMightExistingModelArgs(const css::uno::Sequence< css::beans::PropertyValue >& lOutsideDescriptor) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir ::comphelper::MediaDescriptor lDescriptor(lOutsideDescriptor); 235cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel = lDescriptor.getUnpackedValueOrDefault( 236cdf0e10cSrcweir ::comphelper::MediaDescriptor::PROP_MODEL (), 237cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > ()); 238cdf0e10cSrcweir if (xModel.is ()) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir ::comphelper::MediaDescriptor lModelDescriptor(xModel->getArgs()); 241cdf0e10cSrcweir ::comphelper::MediaDescriptor::iterator pIt = lModelDescriptor.find( ::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE() ); 242cdf0e10cSrcweir if ( pIt != lModelDescriptor.end() ) 243cdf0e10cSrcweir lDescriptor[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] = pIt->second; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir return lDescriptor; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir /*----------------------------------------------- 250cdf0e10cSrcweir 20.08.2003 09:49 251cdf0e10cSrcweir -----------------------------------------------*/ 252cdf0e10cSrcweir void LoadEnv::initializeLoading(const ::rtl::OUString& sURL , 253cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor, 254cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xBaseFrame , 255cdf0e10cSrcweir const ::rtl::OUString& sTarget , 256cdf0e10cSrcweir sal_Int32 nSearchFlags , 257cdf0e10cSrcweir EFeature eFeature , // => use default ... 258cdf0e10cSrcweir EContentType eContentType ) // => use default ... 259cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // SAFE -> ---------------------------------- 262cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 263cdf0e10cSrcweir 264cdf0e10cSrcweir // Handle still running processes! 265cdf0e10cSrcweir if (m_xAsynchronousJob.is()) 266cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING); 267cdf0e10cSrcweir 268cdf0e10cSrcweir // take over all new parameters. 269cdf0e10cSrcweir m_xTargetFrame.clear(); 270cdf0e10cSrcweir m_xBaseFrame = xBaseFrame ; 271cdf0e10cSrcweir m_lMediaDescriptor = impl_mergeMediaDescriptorWithMightExistingModelArgs(lMediaDescriptor); 272cdf0e10cSrcweir m_sTarget = sTarget ; 273cdf0e10cSrcweir m_nSearchFlags = nSearchFlags ; 274cdf0e10cSrcweir m_eFeature = eFeature ; 275cdf0e10cSrcweir m_eContentType = eContentType ; 276cdf0e10cSrcweir m_bCloseFrameOnError = sal_False ; 277cdf0e10cSrcweir m_bReactivateControllerOnError = sal_False ; 278cdf0e10cSrcweir m_bLoaded = sal_False ; 279cdf0e10cSrcweir 280cdf0e10cSrcweir // try to find out, if its realy a content, which can be loaded or must be "handled" 281cdf0e10cSrcweir // We use a default value for this in-parameter. Then we have to start a complex check method 282cdf0e10cSrcweir // internaly. But if this check was already done outside it can be supressed to perform 283cdf0e10cSrcweir // the load request. We take over the result then! 284cdf0e10cSrcweir if (m_eContentType == E_UNSUPPORTED_CONTENT) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir m_eContentType = LoadEnv::classifyContent(sURL, lMediaDescriptor); 287cdf0e10cSrcweir if (m_eContentType == E_UNSUPPORTED_CONTENT) 288cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir // make URL part of the MediaDescriptor 292cdf0e10cSrcweir // It doesnt mater, if its already an item of it. 293cdf0e10cSrcweir // It must be the same value ... so we can overwrite it :-) 294cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_URL()] <<= sURL; 295cdf0e10cSrcweir 296cdf0e10cSrcweir // parse it - because some following code require that 297cdf0e10cSrcweir m_aURL.Complete = sURL; 298cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY); 299cdf0e10cSrcweir xParser->parseStrict(m_aURL); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // BTW: Split URL and JumpMark ... 302cdf0e10cSrcweir // Because such mark is an explicit value of the media descriptor! 303cdf0e10cSrcweir if (m_aURL.Mark.getLength()) 304cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_JUMPMARK()] <<= m_aURL.Mark; 305cdf0e10cSrcweir 306cdf0e10cSrcweir // By the way: remove the old and deprecated value "FileName" from the descriptor! 307cdf0e10cSrcweir ::comphelper::MediaDescriptor::iterator pIt = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_FILENAME()); 308cdf0e10cSrcweir if (pIt != m_lMediaDescriptor.end()) 309cdf0e10cSrcweir m_lMediaDescriptor.erase(pIt); 310cdf0e10cSrcweir 311cdf0e10cSrcweir // patch the MediaDescriptor, so it fullfill the outside requirements 312cdf0e10cSrcweir // Means especialy items like e.g. UI InteractionHandler, Status Indicator, 313cdf0e10cSrcweir // MacroExecutionMode etcpp. 314cdf0e10cSrcweir 315cdf0e10cSrcweir /*TODO progress is bound to a frame ... How can we set it here? */ 316cdf0e10cSrcweir 317cdf0e10cSrcweir // UI mode 318cdf0e10cSrcweir const bool bUIMode = 319cdf0e10cSrcweir ( ( m_eFeature & E_WORK_WITH_UI ) == E_WORK_WITH_UI ) && 320cdf0e10cSrcweir ( m_lMediaDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False ) == sal_False ) && 321cdf0e10cSrcweir ( m_lMediaDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_PREVIEW(), sal_False ) == sal_False ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir initializeUIDefaults( 324cdf0e10cSrcweir m_xSMGR, 325cdf0e10cSrcweir m_lMediaDescriptor, 326cdf0e10cSrcweir bUIMode, 327cdf0e10cSrcweir &m_pQuietInteraction 328cdf0e10cSrcweir ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir aWriteLock.unlock(); 331cdf0e10cSrcweir // <- SAFE ---------------------------------- 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir /*----------------------------------------------- 335cdf0e10cSrcweir 22.01.2010 336cdf0e10cSrcweir -----------------------------------------------*/ 337cdf0e10cSrcweir void LoadEnv::initializeUIDefaults( const css::uno::Reference< css::lang::XMultiServiceFactory >& i_rSMGR, 338cdf0e10cSrcweir ::comphelper::MediaDescriptor& io_lMediaDescriptor, const bool i_bUIMode, 339cdf0e10cSrcweir QuietInteraction** o_ppQuietInteraction ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xInteractionHandler; 342cdf0e10cSrcweir sal_Int16 nMacroMode ; 343cdf0e10cSrcweir sal_Int16 nUpdateMode ; 344cdf0e10cSrcweir 345cdf0e10cSrcweir if ( i_bUIMode ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir nMacroMode = css::document::MacroExecMode::USE_CONFIG; 348cdf0e10cSrcweir nUpdateMode = css::document::UpdateDocMode::ACCORDING_TO_CONFIG; 349cdf0e10cSrcweir try 350cdf0e10cSrcweir { 351cdf0e10cSrcweir xInteractionHandler = css::uno::Reference< css::task::XInteractionHandler >(i_rSMGR->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER), css::uno::UNO_QUERY); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir catch(const css::uno::RuntimeException&) {throw;} 354cdf0e10cSrcweir catch(const css::uno::Exception& ) { } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir // hidden mode 357cdf0e10cSrcweir else 358cdf0e10cSrcweir { 359cdf0e10cSrcweir nMacroMode = css::document::MacroExecMode::NEVER_EXECUTE; 360cdf0e10cSrcweir nUpdateMode = css::document::UpdateDocMode::NO_UPDATE; 361cdf0e10cSrcweir QuietInteraction* pQuietInteraction = new QuietInteraction(); 362cdf0e10cSrcweir xInteractionHandler = css::uno::Reference< css::task::XInteractionHandler >(static_cast< css::task::XInteractionHandler* >(pQuietInteraction), css::uno::UNO_QUERY); 363cdf0e10cSrcweir if ( o_ppQuietInteraction != NULL ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir *o_ppQuietInteraction = pQuietInteraction; 366cdf0e10cSrcweir (*o_ppQuietInteraction)->acquire(); 367cdf0e10cSrcweir } 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir if ( 371cdf0e10cSrcweir (xInteractionHandler.is() ) && 372cdf0e10cSrcweir (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()) == io_lMediaDescriptor.end()) 373cdf0e10cSrcweir ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteractionHandler; 376cdf0e10cSrcweir } 377cdf0e10cSrcweir 378cdf0e10cSrcweir if (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()) == io_lMediaDescriptor.end()) 379cdf0e10cSrcweir io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE()] <<= nMacroMode; 380cdf0e10cSrcweir 381cdf0e10cSrcweir if (io_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()) == io_lMediaDescriptor.end()) 382cdf0e10cSrcweir io_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_UPDATEDOCMODE()] <<= nUpdateMode; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir /*----------------------------------------------- 386cdf0e10cSrcweir 15.08.2003 08:16 387cdf0e10cSrcweir -----------------------------------------------*/ 388cdf0e10cSrcweir void LoadEnv::startLoading() 389cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir // SAFE -> 392cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 393cdf0e10cSrcweir 394cdf0e10cSrcweir // Handle still running processes! 395cdf0e10cSrcweir if (m_xAsynchronousJob.is()) 396cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING); 397cdf0e10cSrcweir 398cdf0e10cSrcweir // content can not be loaded or handled 399cdf0e10cSrcweir // check "classifyContent()" failed before ... 400cdf0e10cSrcweir if (m_eContentType == E_UNSUPPORTED_CONTENT) 401cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT); 402cdf0e10cSrcweir 403cdf0e10cSrcweir // <- SAFE 404cdf0e10cSrcweir aReadLock.unlock(); 405cdf0e10cSrcweir 406cdf0e10cSrcweir // detect its type/filter etcpp. 407cdf0e10cSrcweir // These information will be available by the 408cdf0e10cSrcweir // used descriptor member afterwards and is needed 409cdf0e10cSrcweir // for all following operations! 410cdf0e10cSrcweir // Note: An exception will be thrown, in case operation was not successfully ... 411cdf0e10cSrcweir if (m_eContentType != E_CAN_BE_SET)/* Attention: special feature to set existing component on a frame must ignore type detection! */ 412cdf0e10cSrcweir impl_detectTypeAndFilter(); 413cdf0e10cSrcweir 414cdf0e10cSrcweir // start loading the content ... 415cdf0e10cSrcweir // Attention: Dont check m_eContentType deeper then UNSUPPORTED/SUPPORTED! 416cdf0e10cSrcweir // Because it was made in th easiest way ... may a flat detection was made only. 417cdf0e10cSrcweir // And such simple detection can fail some times .-) 418cdf0e10cSrcweir // Use another strategy here. Try it and let it run into the case "loading not possible". 419cdf0e10cSrcweir sal_Bool bStarted = sal_False; 420cdf0e10cSrcweir if ( 421cdf0e10cSrcweir ((m_eFeature & E_ALLOW_CONTENTHANDLER) == E_ALLOW_CONTENTHANDLER) && 422cdf0e10cSrcweir (m_eContentType != E_CAN_BE_SET ) /* Attention: special feature to set existing component on a frame must ignore type detection! */ 423cdf0e10cSrcweir ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir bStarted = impl_handleContent(); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir if (!bStarted) 429cdf0e10cSrcweir bStarted = impl_loadContent(); 430cdf0e10cSrcweir 431cdf0e10cSrcweir // not started => general error 432cdf0e10cSrcweir // We cant say - what was the reason for. 433cdf0e10cSrcweir if (!bStarted) 434cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_GENERAL_ERROR); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir /*----------------------------------------------- 438cdf0e10cSrcweir 15.08.2003 09:50 439cdf0e10cSrcweir TODO 440cdf0e10cSrcweir First draft does not implement timeout using [ms]. 441cdf0e10cSrcweir Current implementation counts yield calls only ... 442cdf0e10cSrcweir -----------------------------------------------*/ 443cdf0e10cSrcweir sal_Bool LoadEnv::waitWhileLoading(sal_uInt32 nTimeout) 444cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir // Because its not a good idea to block the main thread 447cdf0e10cSrcweir // (and we cant be shure that we are currently not used inside the 448cdf0e10cSrcweir // main thread!), we cant use conditions here realy. We must yield 449cdf0e10cSrcweir // in an intellegent manner :-) 450cdf0e10cSrcweir 451cdf0e10cSrcweir sal_Int32 nTime = nTimeout; 452cdf0e10cSrcweir while(true) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir // SAFE -> ------------------------------ 455cdf0e10cSrcweir ReadGuard aReadLock1(m_aLock); 456cdf0e10cSrcweir if (!m_xAsynchronousJob.is()) 457cdf0e10cSrcweir break; 458cdf0e10cSrcweir aReadLock1.unlock(); 459cdf0e10cSrcweir // <- SAFE ------------------------------ 460cdf0e10cSrcweir 461cdf0e10cSrcweir Application::Yield(); 462cdf0e10cSrcweir 463cdf0e10cSrcweir // forever! 464cdf0e10cSrcweir if (nTimeout==0) 465cdf0e10cSrcweir continue; 466cdf0e10cSrcweir 467cdf0e10cSrcweir // timed out? 468cdf0e10cSrcweir --nTime; 469cdf0e10cSrcweir if (nTime<1) 470cdf0e10cSrcweir break; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir // SAFE -> ---------------------------------- 474cdf0e10cSrcweir ReadGuard aReadLock2(m_aLock); 475cdf0e10cSrcweir return !m_xAsynchronousJob.is(); 476cdf0e10cSrcweir // <- SAFE ---------------------------------- 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir /*----------------------------------------------- 480cdf0e10cSrcweir 20.08.2003 10:00 481cdf0e10cSrcweir -----------------------------------------------*/ 482cdf0e10cSrcweir void LoadEnv::cancelLoading() 483cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir // PARTIAL(!) SAFE -> ------------------------------ 486cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 487cdf0e10cSrcweir 488cdf0e10cSrcweir // Still running? Might waitWhileLoading() 489cdf0e10cSrcweir // runned into the timeout! 490cdf0e10cSrcweir if (m_xAsynchronousJob.is()) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir // try to cancel it ... if its an asynchronous frame loader 493cdf0e10cSrcweir css::uno::Reference< css::frame::XFrameLoader > xAsyncLoader(m_xAsynchronousJob, css::uno::UNO_QUERY); 494cdf0e10cSrcweir if (xAsyncLoader.is()) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir aReadLock.unlock(); 497cdf0e10cSrcweir // <- BREAK SAFE ------------------------------ 498cdf0e10cSrcweir xAsyncLoader->cancel(); 499cdf0e10cSrcweir // <- RESTART SAFE ---------------------------- 500cdf0e10cSrcweir aReadLock.lock(); 501cdf0e10cSrcweir /* Attention: 502cdf0e10cSrcweir After returning from any cancel/dispose call, neither the frame nor weself 503cdf0e10cSrcweir may be called back. Because only we can cancel this job, we already know 504cdf0e10cSrcweir the result! => Thats why its not usefull nor neccessary to wait for any 505cdf0e10cSrcweir asynchronous listener notification. 506cdf0e10cSrcweir */ 507cdf0e10cSrcweir m_bLoaded = sal_False; 508cdf0e10cSrcweir m_xAsynchronousJob.clear(); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir // or may be its a content handler? Such handler cant be cancelled in its running 511cdf0e10cSrcweir // operation :-( And we cant deregister us there again :-( 512cdf0e10cSrcweir // => The only chance is an exception :-) 513cdf0e10cSrcweir else 514cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir impl_reactForLoadingState(); 518cdf0e10cSrcweir 519cdf0e10cSrcweir aReadLock.unlock(); 520cdf0e10cSrcweir // <- PARTIAL(!) SAFE ------------------------------ 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir /*----------------------------------------------- 524cdf0e10cSrcweir 14.08.2003 13:33 525cdf0e10cSrcweir -----------------------------------------------*/ 526cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::getTarget() const 527cdf0e10cSrcweir { 528cdf0e10cSrcweir // SAFE -> 529cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 530cdf0e10cSrcweir return m_xTargetFrame; 531cdf0e10cSrcweir // <- SAFE 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir /*----------------------------------------------- 535cdf0e10cSrcweir 14.08.2003 13:35 536cdf0e10cSrcweir -----------------------------------------------*/ 537cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > LoadEnv::getTargetComponent() const 538cdf0e10cSrcweir { 539cdf0e10cSrcweir // SAFE -> 540cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 541cdf0e10cSrcweir 542cdf0e10cSrcweir if (!m_xTargetFrame.is()) 543cdf0e10cSrcweir return css::uno::Reference< css::lang::XComponent >(); 544cdf0e10cSrcweir 545cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = m_xTargetFrame->getController(); 546cdf0e10cSrcweir if (!xController.is()) 547cdf0e10cSrcweir return css::uno::Reference< css::lang::XComponent >(m_xTargetFrame->getComponentWindow(), css::uno::UNO_QUERY); 548cdf0e10cSrcweir 549cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel = xController->getModel(); 550cdf0e10cSrcweir if (!xModel.is()) 551cdf0e10cSrcweir return css::uno::Reference< css::lang::XComponent >(xController, css::uno::UNO_QUERY); 552cdf0e10cSrcweir 553cdf0e10cSrcweir return css::uno::Reference< css::lang::XComponent >(xModel, css::uno::UNO_QUERY); 554cdf0e10cSrcweir // <- SAFE 555cdf0e10cSrcweir } 556cdf0e10cSrcweir 557cdf0e10cSrcweir /*----------------------------------------------- 558cdf0e10cSrcweir 15.08.2003 11:15 559cdf0e10cSrcweir -----------------------------------------------*/ 560cdf0e10cSrcweir void SAL_CALL LoadEnvListener::loadFinished(const css::uno::Reference< css::frame::XFrameLoader >&) 561cdf0e10cSrcweir throw(css::uno::RuntimeException) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir // SAFE -> ---------------------------------- 564cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 565cdf0e10cSrcweir 566cdf0e10cSrcweir if (m_ppCheck && *m_ppCheck) 567cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_True); 568cdf0e10cSrcweir m_ppCheck = NULL; 569cdf0e10cSrcweir 570cdf0e10cSrcweir aWriteLock.unlock(); 571cdf0e10cSrcweir // <- SAFE ---------------------------------- 572cdf0e10cSrcweir } 573cdf0e10cSrcweir 574cdf0e10cSrcweir /*----------------------------------------------- 575cdf0e10cSrcweir 14.10.2003 12:23 576cdf0e10cSrcweir -----------------------------------------------*/ 577cdf0e10cSrcweir void SAL_CALL LoadEnvListener::loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >&) 578cdf0e10cSrcweir throw(css::uno::RuntimeException) 579cdf0e10cSrcweir { 580cdf0e10cSrcweir // SAFE -> ---------------------------------- 581cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 582cdf0e10cSrcweir 583cdf0e10cSrcweir if (m_ppCheck && *m_ppCheck) 584cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_False); 585cdf0e10cSrcweir m_ppCheck = NULL; 586cdf0e10cSrcweir 587cdf0e10cSrcweir aWriteLock.unlock(); 588cdf0e10cSrcweir // <- SAFE ---------------------------------- 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir /*----------------------------------------------- 592cdf0e10cSrcweir 14.10.2003 12:23 593cdf0e10cSrcweir -----------------------------------------------*/ 594cdf0e10cSrcweir void SAL_CALL LoadEnvListener::dispatchFinished(const css::frame::DispatchResultEvent& aEvent) 595cdf0e10cSrcweir throw(css::uno::RuntimeException) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir // SAFE -> ---------------------------------- 598cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 599cdf0e10cSrcweir 600cdf0e10cSrcweir if (!m_ppCheck || !*m_ppCheck) 601cdf0e10cSrcweir return; 602cdf0e10cSrcweir 603cdf0e10cSrcweir switch(aEvent.State) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir case css::frame::DispatchResultState::FAILURE : 606cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_False); 607cdf0e10cSrcweir break; 608cdf0e10cSrcweir 609cdf0e10cSrcweir case css::frame::DispatchResultState::SUCCESS : 610cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_False); 611cdf0e10cSrcweir break; 612cdf0e10cSrcweir 613cdf0e10cSrcweir case css::frame::DispatchResultState::DONTKNOW : 614cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_False); 615cdf0e10cSrcweir break; 616cdf0e10cSrcweir } 617cdf0e10cSrcweir m_ppCheck = NULL; 618cdf0e10cSrcweir 619cdf0e10cSrcweir aWriteLock.unlock(); 620cdf0e10cSrcweir // <- SAFE ---------------------------------- 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir /*----------------------------------------------- 624cdf0e10cSrcweir 14.10.2003 12:24 625cdf0e10cSrcweir -----------------------------------------------*/ 626cdf0e10cSrcweir void SAL_CALL LoadEnvListener::disposing(const css::lang::EventObject&) 627cdf0e10cSrcweir throw(css::uno::RuntimeException) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir // SAFE -> ---------------------------------- 630cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 631cdf0e10cSrcweir 632cdf0e10cSrcweir if (m_ppCheck && *m_ppCheck) 633cdf0e10cSrcweir m_pLoadEnv->impl_setResult(sal_False); 634cdf0e10cSrcweir m_ppCheck = NULL; 635cdf0e10cSrcweir 636cdf0e10cSrcweir aWriteLock.unlock(); 637cdf0e10cSrcweir // <- SAFE ---------------------------------- 638cdf0e10cSrcweir } 639cdf0e10cSrcweir 640cdf0e10cSrcweir /*----------------------------------------------- 641cdf0e10cSrcweir 14.10.2003 12:20 642cdf0e10cSrcweir -----------------------------------------------*/ 643cdf0e10cSrcweir void LoadEnv::impl_setResult(sal_Bool bResult) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir // SAFE -> ---------------------------------- 646cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 647cdf0e10cSrcweir 648cdf0e10cSrcweir m_bLoaded = bResult; 649cdf0e10cSrcweir 650cdf0e10cSrcweir impl_reactForLoadingState(); 651cdf0e10cSrcweir 652cdf0e10cSrcweir // clearing of this reference will unblock waitWhileLoading()! 653cdf0e10cSrcweir // So we must be shure, that loading process was realy finished. 654cdf0e10cSrcweir // => do it as last operation of this method ... 655cdf0e10cSrcweir m_xAsynchronousJob.clear(); 656cdf0e10cSrcweir 657cdf0e10cSrcweir aWriteLock.unlock(); 658cdf0e10cSrcweir // <- SAFE ---------------------------------- 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir /*----------------------------------------------- 662cdf0e10cSrcweir 06.02.2004 14:03 663cdf0e10cSrcweir TODO: Is it a good idea to change Sequence<> 664cdf0e10cSrcweir parameter to stl-adapter? 665cdf0e10cSrcweir -----------------------------------------------*/ 666cdf0e10cSrcweir LoadEnv::EContentType LoadEnv::classifyContent(const ::rtl::OUString& sURL , 667cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir //------------------------------------------- 670cdf0e10cSrcweir // (i) Filter some special well known URL protocols, 671cdf0e10cSrcweir // which can not be handled or loaded in general. 672cdf0e10cSrcweir // Of course an empty URL must be ignored here too. 673cdf0e10cSrcweir // Note: These URL schemata are fix and well known ... 674cdf0e10cSrcweir // But there can be some additional ones, which was not 675cdf0e10cSrcweir // defined at implementation time of this class :-( 676cdf0e10cSrcweir // So we have to make shure, that the following code 677cdf0e10cSrcweir // can detect such protocol schemata too :-) 678cdf0e10cSrcweir 679cdf0e10cSrcweir if( 680cdf0e10cSrcweir (!sURL.getLength() ) || 681cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_UNO )) || 682cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SLOT )) || 683cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MACRO )) || 684cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SERVICE)) || 685cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MAILTO )) || 686cdf0e10cSrcweir (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_NEWS )) 687cdf0e10cSrcweir ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir return E_UNSUPPORTED_CONTENT; 690cdf0e10cSrcweir } 691cdf0e10cSrcweir 692cdf0e10cSrcweir //------------------------------------------- 693cdf0e10cSrcweir // (ii) Some special URLs indicates a given input stream, 694cdf0e10cSrcweir // a full featured document model directly or 695cdf0e10cSrcweir // specify a request for opening an empty document. 696cdf0e10cSrcweir // Such contents are loadable in general. 697cdf0e10cSrcweir // But we have to check, if the media descriptor contains 698cdf0e10cSrcweir // all needed resources. If they are missing - the following 699cdf0e10cSrcweir // load request will fail. 700cdf0e10cSrcweir 701cdf0e10cSrcweir /* Attention: The following code cant work on such special URLs! 702cdf0e10cSrcweir It should not break the office .. but it make no sense 703cdf0e10cSrcweir to start expensive object creations and complex search 704cdf0e10cSrcweir algorithm if its clear, that such URLs must be handled 705cdf0e10cSrcweir in a special way .-) 706cdf0e10cSrcweir */ 707cdf0e10cSrcweir 708cdf0e10cSrcweir // creation of new documents 709cdf0e10cSrcweir if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_FACTORY)) 710cdf0e10cSrcweir return E_CAN_BE_LOADED; 711cdf0e10cSrcweir 712cdf0e10cSrcweir // using of an existing input stream 713cdf0e10cSrcweir ::comphelper::MediaDescriptor stlMediaDescriptor(lMediaDescriptor); 714cdf0e10cSrcweir ::comphelper::MediaDescriptor::const_iterator pIt; 715cdf0e10cSrcweir if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_STREAM)) 716cdf0e10cSrcweir { 717cdf0e10cSrcweir pIt = stlMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_INPUTSTREAM()); 718cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xStream; 719cdf0e10cSrcweir if (pIt != stlMediaDescriptor.end()) 720cdf0e10cSrcweir pIt->second >>= xStream; 721cdf0e10cSrcweir if (xStream.is()) 722cdf0e10cSrcweir return E_CAN_BE_LOADED; 723cdf0e10cSrcweir LOG_WARNING("LoadEnv::classifyContent()", "loading from stream with right URL but invalid stream detected") 724cdf0e10cSrcweir return E_UNSUPPORTED_CONTENT; 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir // using of a full featured document 728cdf0e10cSrcweir if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_OBJECT)) 729cdf0e10cSrcweir { 730cdf0e10cSrcweir pIt = stlMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_MODEL()); 731cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel; 732cdf0e10cSrcweir if (pIt != stlMediaDescriptor.end()) 733cdf0e10cSrcweir pIt->second >>= xModel; 734cdf0e10cSrcweir if (xModel.is()) 735cdf0e10cSrcweir return E_CAN_BE_SET; 736cdf0e10cSrcweir LOG_WARNING("LoadEnv::classifyContent()", "loading with object with right URL but invalid object detected") 737cdf0e10cSrcweir return E_UNSUPPORTED_CONTENT; 738cdf0e10cSrcweir } 739cdf0e10cSrcweir 740cdf0e10cSrcweir // following operatons can work on an internal type name only :-( 741cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory(); 742cdf0e10cSrcweir css::uno::Reference< css::document::XTypeDetection > xDetect(xSMGR->createInstance(SERVICENAME_TYPEDETECTION), css::uno::UNO_QUERY); 743cdf0e10cSrcweir 744cdf0e10cSrcweir ::rtl::OUString sType = xDetect->queryTypeByURL(sURL); 745cdf0e10cSrcweir 746cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lQuery(1) ; 747cdf0e10cSrcweir css::uno::Reference< css::container::XContainerQuery > xContainer ; 748cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xSet ; 749cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lTypesReg(1); 750cdf0e10cSrcweir 751cdf0e10cSrcweir /* 752cdf0e10cSrcweir //------------------------------------------- 753cdf0e10cSrcweir lQuery[0].Name = ::framework::constant::Filter::PROP_TYPE; 754cdf0e10cSrcweir lQuery[0].Value <<= sType; 755cdf0e10cSrcweir 756cdf0e10cSrcweir xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_FILTERFACTORY), css::uno::UNO_QUERY); 757cdf0e10cSrcweir xSet = xContainer->createSubSetEnumerationByProperties(lQuery); 758cdf0e10cSrcweir // at least one registered frame loader is enough! 759cdf0e10cSrcweir if (xSet->hasMoreElements()) 760cdf0e10cSrcweir return E_CAN_BE_LOADED; 761cdf0e10cSrcweir */ 762cdf0e10cSrcweir 763cdf0e10cSrcweir //------------------------------------------- 764cdf0e10cSrcweir // (iii) If a FrameLoader service (or at least 765cdf0e10cSrcweir // a Filter) can be found, which supports 766cdf0e10cSrcweir // this URL - it must be a loadable content. 767cdf0e10cSrcweir // Because both items are registered for types 768cdf0e10cSrcweir // its enough to check for frame loaders only. 769cdf0e10cSrcweir // Mos of our filters are handled by our global 770cdf0e10cSrcweir // default loader. But there exist some specialized 771cdf0e10cSrcweir // loader, which does not work on top of filters! 772cdf0e10cSrcweir // So its not enough to search on the filter configuration. 773cdf0e10cSrcweir // Further its not enough to search for types! 774cdf0e10cSrcweir // Because there exist some types, which are referenced by 775cdf0e10cSrcweir // other objects ... but not by filters nor frame loaders! 776cdf0e10cSrcweir 777cdf0e10cSrcweir lTypesReg[0] = sType; 778cdf0e10cSrcweir lQuery[0].Name = ::framework::constant::FrameLoader::PROP_TYPES; 779cdf0e10cSrcweir lQuery[0].Value <<= lTypesReg; 780cdf0e10cSrcweir 781cdf0e10cSrcweir xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_FRAMELOADERFACTORY), css::uno::UNO_QUERY); 782cdf0e10cSrcweir xSet = xContainer->createSubSetEnumerationByProperties(lQuery); 783cdf0e10cSrcweir // at least one registered frame loader is enough! 784cdf0e10cSrcweir if (xSet->hasMoreElements()) 785cdf0e10cSrcweir return E_CAN_BE_LOADED; 786cdf0e10cSrcweir 787cdf0e10cSrcweir //------------------------------------------- 788cdf0e10cSrcweir // (iv) Some URL protocols are supported by special services. 789cdf0e10cSrcweir // E.g. ContentHandler. 790cdf0e10cSrcweir // Such contents can be handled ... but not loaded. 791cdf0e10cSrcweir 792cdf0e10cSrcweir lTypesReg[0] = sType; 793cdf0e10cSrcweir lQuery[0].Name = ::framework::constant::ContentHandler::PROP_TYPES; 794cdf0e10cSrcweir lQuery[0].Value <<= lTypesReg; 795cdf0e10cSrcweir 796cdf0e10cSrcweir xContainer = css::uno::Reference< css::container::XContainerQuery >(xSMGR->createInstance(SERVICENAME_CONTENTHANDLERFACTORY), css::uno::UNO_QUERY); 797cdf0e10cSrcweir xSet = xContainer->createSubSetEnumerationByProperties(lQuery); 798cdf0e10cSrcweir // at least one registered content handler is enough! 799cdf0e10cSrcweir if (xSet->hasMoreElements()) 800cdf0e10cSrcweir return E_CAN_BE_HANDLED; 801cdf0e10cSrcweir 802cdf0e10cSrcweir //------------------------------------------- 803cdf0e10cSrcweir // (v) Last but not least the UCB is used inside office to 804cdf0e10cSrcweir // load contents. He has a special configuration to know 805cdf0e10cSrcweir // which URL schemata can be used inside office. 806cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentProviderManager > xUCB(xSMGR->createInstance(SERVICENAME_UCBCONTENTBROKER), css::uno::UNO_QUERY); 807cdf0e10cSrcweir if (xUCB->queryContentProvider(sURL).is()) 808cdf0e10cSrcweir return E_CAN_BE_LOADED; 809cdf0e10cSrcweir 810cdf0e10cSrcweir //------------------------------------------- 811cdf0e10cSrcweir // (TODO) At this point, we have no idea .-) 812cdf0e10cSrcweir // But it seems to be better, to break all 813cdf0e10cSrcweir // further requests for this URL. Otherwhise 814cdf0e10cSrcweir // we can run into some trouble. 815cdf0e10cSrcweir return E_UNSUPPORTED_CONTENT; 816cdf0e10cSrcweir } 817cdf0e10cSrcweir 818cdf0e10cSrcweir /*----------------------------------------------- 819cdf0e10cSrcweir 03.11.2003 09:31 820cdf0e10cSrcweir -----------------------------------------------*/ 821cdf0e10cSrcweir void LoadEnv::impl_detectTypeAndFilter() 822cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir static ::rtl::OUString TYPEPROP_PREFERREDFILTER = ::rtl::OUString::createFromAscii("PreferredFilter"); 825cdf0e10cSrcweir static ::rtl::OUString FILTERPROP_FLAGS = ::rtl::OUString::createFromAscii("Flags" ); 826cdf0e10cSrcweir static sal_Int32 FILTERFLAG_TEMPLATEPATH = 16; 827cdf0e10cSrcweir 828cdf0e10cSrcweir // SAFE -> 829cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 830cdf0e10cSrcweir 831cdf0e10cSrcweir // Attention: Because our stl media descriptor is a copy of an uno sequence 832cdf0e10cSrcweir // we cant use as an in/out parameter here. Copy it before and dont forget to 833cdf0e10cSrcweir // update structure afterwards again! 834cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lDescriptor = m_lMediaDescriptor.getAsConstPropertyValueList(); 835cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 836cdf0e10cSrcweir 837cdf0e10cSrcweir aReadLock.unlock(); 838cdf0e10cSrcweir // <- SAFE 839cdf0e10cSrcweir 840cdf0e10cSrcweir ::rtl::OUString sType; 841cdf0e10cSrcweir css::uno::Reference< css::document::XTypeDetection > xDetect(xSMGR->createInstance(SERVICENAME_TYPEDETECTION), css::uno::UNO_QUERY); 842cdf0e10cSrcweir if (xDetect.is()) 843cdf0e10cSrcweir sType = xDetect->queryTypeByDescriptor(lDescriptor, sal_True); /*TODO should deep detection be able for enable/disable it from outside? */ 844cdf0e10cSrcweir 845cdf0e10cSrcweir // no valid content -> loading not possible 846cdf0e10cSrcweir if (!sType.getLength()) 847cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT); 848cdf0e10cSrcweir 849cdf0e10cSrcweir // SAFE -> 850cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 851cdf0e10cSrcweir 852cdf0e10cSrcweir // detection was successfully => update the descriptor member of this class 853cdf0e10cSrcweir m_lMediaDescriptor << lDescriptor; 854cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sType; 855cdf0e10cSrcweir // Is there an already detected (may be preselected) filter? 856cdf0e10cSrcweir // see below ... 857cdf0e10cSrcweir ::rtl::OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_FILTERNAME(), ::rtl::OUString()); 858cdf0e10cSrcweir 859cdf0e10cSrcweir aWriteLock.unlock(); 860cdf0e10cSrcweir // <- SAFE 861cdf0e10cSrcweir 862cdf0e10cSrcweir // But the type isnt enough. For loading sometimes we need more informations. 863cdf0e10cSrcweir // E.g. for our "_default" feature, where we recylce any frame which contains 864cdf0e10cSrcweir // and "Untitled" document, we must know if the new document is based on a template! 865cdf0e10cSrcweir // But this information is available as a filter property only. 866cdf0e10cSrcweir // => We must try(!) to detect the right filter for this load request. 867cdf0e10cSrcweir // On the other side ... if no filter is available .. ignore it. 868cdf0e10cSrcweir // Then the type information must be enough. 869cdf0e10cSrcweir if (!sFilter.getLength()) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir // no -> try to find a preferred filter for the detected type. 872cdf0e10cSrcweir // Dont forget to updatet he media descriptor. 873cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xTypeCont(xDetect, css::uno::UNO_QUERY_THROW); 874cdf0e10cSrcweir try 875cdf0e10cSrcweir { 876cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lTypeProps(xTypeCont->getByName(sType)); 877cdf0e10cSrcweir sFilter = lTypeProps.getUnpackedValueOrDefault(TYPEPROP_PREFERREDFILTER, ::rtl::OUString()); 878cdf0e10cSrcweir if (sFilter.getLength()) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir // SAFE -> 881cdf0e10cSrcweir aWriteLock.lock(); 882cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter; 883cdf0e10cSrcweir aWriteLock.unlock(); 884cdf0e10cSrcweir // <- SAFE 885cdf0e10cSrcweir } 886cdf0e10cSrcweir } 887cdf0e10cSrcweir catch(const css::container::NoSuchElementException&) 888cdf0e10cSrcweir {} 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir // check if the filter (if one exists) points to a template format filter. 892cdf0e10cSrcweir // Then we have to add the property "AsTemplate". 893cdf0e10cSrcweir // We need this information to decide afterwards if we can use a "recycle frame" 894cdf0e10cSrcweir // for target "_default" or has to create a new one everytimes. 895cdf0e10cSrcweir // On the other side we have to supress that, if this property already exists 896cdf0e10cSrcweir // and should trigger a special handling. Then the outside calli of this method here, 897cdf0e10cSrcweir // has to know, what he is doing .-) 898cdf0e10cSrcweir 899cdf0e10cSrcweir sal_Bool bIsOwnTemplate = sal_False; 900cdf0e10cSrcweir if (sFilter.getLength()) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xFilterCont(xSMGR->createInstance(SERVICENAME_FILTERFACTORY), css::uno::UNO_QUERY_THROW); 903cdf0e10cSrcweir try 904cdf0e10cSrcweir { 905cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lFilterProps(xFilterCont->getByName(sFilter)); 906cdf0e10cSrcweir sal_Int32 nFlags = lFilterProps.getUnpackedValueOrDefault(FILTERPROP_FLAGS, (sal_Int32)0); 907cdf0e10cSrcweir bIsOwnTemplate = ((nFlags & FILTERFLAG_TEMPLATEPATH) == FILTERFLAG_TEMPLATEPATH); 908cdf0e10cSrcweir } 909cdf0e10cSrcweir catch(const css::container::NoSuchElementException&) 910cdf0e10cSrcweir {} 911cdf0e10cSrcweir } 912cdf0e10cSrcweir if (bIsOwnTemplate) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir // SAFE -> 915cdf0e10cSrcweir aWriteLock.lock(); 916cdf0e10cSrcweir // Dont overwrite external decisions! See comments before ... 917cdf0e10cSrcweir ::comphelper::MediaDescriptor::const_iterator pAsTemplateItem = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_ASTEMPLATE()); 918cdf0e10cSrcweir if (pAsTemplateItem == m_lMediaDescriptor.end()) 919cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_ASTEMPLATE()] <<= sal_True; 920cdf0e10cSrcweir aWriteLock.unlock(); 921cdf0e10cSrcweir // <- SAFE 922cdf0e10cSrcweir } 923cdf0e10cSrcweir } 924cdf0e10cSrcweir 925cdf0e10cSrcweir /*----------------------------------------------- 926cdf0e10cSrcweir 15.08.2003 09:38 927cdf0e10cSrcweir -----------------------------------------------*/ 928cdf0e10cSrcweir sal_Bool LoadEnv::impl_handleContent() 929cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 930cdf0e10cSrcweir { 931cdf0e10cSrcweir // SAFE -> ----------------------------------- 932cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 933cdf0e10cSrcweir 934cdf0e10cSrcweir // the type must exist inside the descriptor ... otherwhise this class is implemented wrong :-) 935cdf0e10cSrcweir ::rtl::OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString()); 936cdf0e10cSrcweir if (!sType.getLength()) 937cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR); 938cdf0e10cSrcweir 939cdf0e10cSrcweir // convert media descriptor and URL to right format for later interface call! 940cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lDescriptor; 941cdf0e10cSrcweir m_lMediaDescriptor >> lDescriptor; 942cdf0e10cSrcweir css::util::URL aURL = m_aURL; 943cdf0e10cSrcweir 944cdf0e10cSrcweir // get neccessary container to query for a handler object 945cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xFactory(m_xSMGR->createInstance(SERVICENAME_CONTENTHANDLERFACTORY), css::uno::UNO_QUERY); 946cdf0e10cSrcweir css::uno::Reference< css::container::XContainerQuery > xQuery (xFactory , css::uno::UNO_QUERY); 947cdf0e10cSrcweir 948cdf0e10cSrcweir aReadLock.unlock(); 949cdf0e10cSrcweir // <- SAFE ----------------------------------- 950cdf0e10cSrcweir 951cdf0e10cSrcweir // query 952cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lTypeReg(1); 953cdf0e10cSrcweir lTypeReg[0] = sType; 954cdf0e10cSrcweir 955cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lQuery(1); 956cdf0e10cSrcweir lQuery[0].Name = ::framework::constant::ContentHandler::PROP_TYPES; 957cdf0e10cSrcweir lQuery[0].Value <<= lTypeReg; 958cdf0e10cSrcweir 959cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xSet = xQuery->createSubSetEnumerationByProperties(lQuery); 960cdf0e10cSrcweir while(xSet->hasMoreElements()) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lProps (xSet->nextElement()); 963cdf0e10cSrcweir ::rtl::OUString sHandler = lProps.getUnpackedValueOrDefault(::framework::constant::ContentHandler::PROP_NAME, ::rtl::OUString()); 964cdf0e10cSrcweir 965cdf0e10cSrcweir css::uno::Reference< css::frame::XNotifyingDispatch > xHandler; 966cdf0e10cSrcweir try 967cdf0e10cSrcweir { 968cdf0e10cSrcweir xHandler = css::uno::Reference< css::frame::XNotifyingDispatch >(xFactory->createInstance(sHandler), css::uno::UNO_QUERY); 969cdf0e10cSrcweir if (!xHandler.is()) 970cdf0e10cSrcweir continue; 971cdf0e10cSrcweir } 972cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 973cdf0e10cSrcweir { throw; } 974cdf0e10cSrcweir catch(const css::uno::Exception&) 975cdf0e10cSrcweir { continue; } 976cdf0e10cSrcweir 977cdf0e10cSrcweir // SAFE -> ----------------------------------- 978cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 979cdf0e10cSrcweir m_xAsynchronousJob = xHandler; 980cdf0e10cSrcweir m_pCheck = this; 981cdf0e10cSrcweir LoadEnvListener* pListener = new LoadEnvListener(m_pCheck, this); 982cdf0e10cSrcweir aWriteLock.unlock(); 983cdf0e10cSrcweir // <- SAFE ----------------------------------- 984cdf0e10cSrcweir 985cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchResultListener > xListener(static_cast< css::frame::XDispatchResultListener* >(pListener), css::uno::UNO_QUERY); 986cdf0e10cSrcweir xHandler->dispatchWithNotification(aURL, lDescriptor, xListener); 987cdf0e10cSrcweir 988cdf0e10cSrcweir return sal_True; 989cdf0e10cSrcweir } 990cdf0e10cSrcweir 991cdf0e10cSrcweir return sal_False; 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir //----------------------------------------------- 995cdf0e10cSrcweir sal_Bool LoadEnv::impl_furtherDocsAllowed() 996cdf0e10cSrcweir { 997cdf0e10cSrcweir // SAFE -> 998cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 999cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 1000cdf0e10cSrcweir aReadLock.unlock(); 1001cdf0e10cSrcweir // <- SAFE 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir sal_Bool bAllowed = sal_True; 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir try 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 1008cdf0e10cSrcweir xSMGR, 1009cdf0e10cSrcweir ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"), 1010cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Misc"), 1011cdf0e10cSrcweir ::rtl::OUString::createFromAscii("MaxOpenDocuments"), 1012cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY); 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir // NIL means: count of allowed documents = infinite ! 1015cdf0e10cSrcweir // => return sal_True 1016cdf0e10cSrcweir if ( ! aVal.hasValue()) 1017cdf0e10cSrcweir bAllowed = sal_True; 1018cdf0e10cSrcweir else 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir sal_Int32 nMaxOpenDocuments = 0; 1021cdf0e10cSrcweir aVal >>= nMaxOpenDocuments; 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir css::uno::Reference< css::frame::XFramesSupplier > xDesktop( 1024cdf0e10cSrcweir xSMGR->createInstance(SERVICENAME_DESKTOP), 1025cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir FrameListAnalyzer aAnalyzer(xDesktop, 1028cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(), 1029cdf0e10cSrcweir FrameListAnalyzer::E_HELP | 1030cdf0e10cSrcweir FrameListAnalyzer::E_BACKINGCOMPONENT | 1031cdf0e10cSrcweir FrameListAnalyzer::E_HIDDEN); 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir sal_Int32 nOpenDocuments = aAnalyzer.m_lOtherVisibleFrames.getLength(); 1034cdf0e10cSrcweir bAllowed = (nOpenDocuments < nMaxOpenDocuments); 1035cdf0e10cSrcweir } 1036cdf0e10cSrcweir } 1037cdf0e10cSrcweir catch(const css::uno::Exception&) 1038cdf0e10cSrcweir { bAllowed = sal_True; } // !! internal errors are no reason to disturb the office from opening documents .-) 1039cdf0e10cSrcweir 1040cdf0e10cSrcweir if ( ! bAllowed ) 1041cdf0e10cSrcweir { 1042cdf0e10cSrcweir // SAFE -> 1043cdf0e10cSrcweir aReadLock.lock(); 1044cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler > xInteraction = m_lMediaDescriptor.getUnpackedValueOrDefault( 1045cdf0e10cSrcweir ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER(), 1046cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler >()); 1047cdf0e10cSrcweir aReadLock.unlock(); 1048cdf0e10cSrcweir // <- SAFE 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir if (xInteraction.is()) 1051cdf0e10cSrcweir { 1052cdf0e10cSrcweir css::uno::Any aInteraction; 1053cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations(2); 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir comphelper::OInteractionAbort* pAbort = new comphelper::OInteractionAbort(); 1056cdf0e10cSrcweir comphelper::OInteractionApprove* pApprove = new comphelper::OInteractionApprove(); 1057cdf0e10cSrcweir 1058cdf0e10cSrcweir lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >( 1059cdf0e10cSrcweir static_cast< css::task::XInteractionContinuation* >(pAbort), 1060cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 1061cdf0e10cSrcweir lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >( 1062cdf0e10cSrcweir static_cast< css::task::XInteractionContinuation* >(pApprove), 1063cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir css::task::ErrorCodeRequest aErrorCode; 1066cdf0e10cSrcweir aErrorCode.ErrCode = ERRCODE_SFX_NOMOREDOCUMENTSALLOWED; 1067cdf0e10cSrcweir aInteraction <<= aErrorCode; 1068cdf0e10cSrcweir xInteraction->handle( InteractionRequest::CreateRequest(aInteraction, lContinuations) ); 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir } 1071cdf0e10cSrcweir 1072cdf0e10cSrcweir return bAllowed; 1073cdf0e10cSrcweir } 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir //----------------------------------------------- 1076cdf0e10cSrcweir sal_Bool LoadEnv::impl_loadContent() 1077cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 1078cdf0e10cSrcweir { 1079cdf0e10cSrcweir // SAFE -> ----------------------------------- 1080cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1081cdf0e10cSrcweir 1082cdf0e10cSrcweir // search or create right target frame 1083cdf0e10cSrcweir ::rtl::OUString sTarget = m_sTarget; 1084cdf0e10cSrcweir if (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT)) 1085cdf0e10cSrcweir { 1086cdf0e10cSrcweir m_xTargetFrame = impl_searchAlreadyLoaded(); 1087cdf0e10cSrcweir if (m_xTargetFrame.is()) 1088cdf0e10cSrcweir { 1089cdf0e10cSrcweir impl_setResult(sal_True); 1090cdf0e10cSrcweir return sal_True; 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir m_xTargetFrame = impl_searchRecycleTarget(); 1093cdf0e10cSrcweir } 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir if (! m_xTargetFrame.is()) 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir if ( 1098cdf0e10cSrcweir (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_BLANK )) || 1099cdf0e10cSrcweir (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT)) 1100cdf0e10cSrcweir ) 1101cdf0e10cSrcweir { 1102cdf0e10cSrcweir if (! impl_furtherDocsAllowed()) 1103cdf0e10cSrcweir return sal_False; 1104cdf0e10cSrcweir m_xTargetFrame = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0); 1105cdf0e10cSrcweir m_bCloseFrameOnError = m_xTargetFrame.is(); 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir else 1108cdf0e10cSrcweir { 1109cdf0e10cSrcweir sal_Int32 nFlags = m_nSearchFlags & ~css::frame::FrameSearchFlag::CREATE; 1110cdf0e10cSrcweir m_xTargetFrame = m_xBaseFrame->findFrame(sTarget, nFlags); 1111cdf0e10cSrcweir if (! m_xTargetFrame.is()) 1112cdf0e10cSrcweir { 1113cdf0e10cSrcweir if (! impl_furtherDocsAllowed()) 1114cdf0e10cSrcweir return sal_False; 1115cdf0e10cSrcweir m_xTargetFrame = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0); 1116cdf0e10cSrcweir m_bCloseFrameOnError = m_xTargetFrame.is(); 1117cdf0e10cSrcweir } 1118cdf0e10cSrcweir } 1119cdf0e10cSrcweir } 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir // If we couldn't find a valid frame or the frame has no container window 1122cdf0e10cSrcweir // we have to throw an exception. 1123cdf0e10cSrcweir if ( 1124cdf0e10cSrcweir ( ! m_xTargetFrame.is() ) || 1125cdf0e10cSrcweir ( ! m_xTargetFrame->getContainerWindow().is() ) 1126cdf0e10cSrcweir ) 1127cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_NO_TARGET_FOUND); 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xTargetFrame = m_xTargetFrame; 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir // Now we have a valid frame ... and type detection was already done. 1132cdf0e10cSrcweir // We should apply the module dependend window position and size to the 1133cdf0e10cSrcweir // frame window. 1134cdf0e10cSrcweir impl_applyPersistentWindowState(xTargetFrame->getContainerWindow()); 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir // Don't forget to lock task for following load process. Otherwise it could die 1137cdf0e10cSrcweir // during this operation runs by terminating the office or closing this task via api. 1138cdf0e10cSrcweir // If we set this lock "close()" will return false and closing will be broken. 1139cdf0e10cSrcweir // Attention: Don't forget to reset this lock again after finishing operation. 1140cdf0e10cSrcweir // Otherwise task AND office couldn't die!!! 1141cdf0e10cSrcweir // This includes gracefully handling of Exceptions (Runtime!) too ... 1142cdf0e10cSrcweir // Thats why we use a specialized guard, which will reset the lock 1143cdf0e10cSrcweir // if it will be run out of scope. 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir // Note further: ignore if this internal guard already contains a resource. 1146cdf0e10cSrcweir // Might impl_searchRecylcTarget() set it before. But incase this impl-method wasnt used 1147cdf0e10cSrcweir // and the target frame was new created ... this lock here must be set! 1148cdf0e10cSrcweir css::uno::Reference< css::document::XActionLockable > xTargetLock(xTargetFrame, css::uno::UNO_QUERY); 1149cdf0e10cSrcweir m_aTargetLock.setResource(xTargetLock); 1150cdf0e10cSrcweir 1151cdf0e10cSrcweir // Add status indicator to descriptor. Loader can show an progresses then. 1152cdf0e10cSrcweir // But don't do it, if loading should be hidden or preview is used ...! 1153cdf0e10cSrcweir // So we prevent our code against wrong using. Why? 1154cdf0e10cSrcweir // It could be, that using of this progress could make trouble. e.g. He make window visible ... 1155cdf0e10cSrcweir // but shouldn't do that. But if no indicator is available ... nobody has a chance to do that! 1156cdf0e10cSrcweir sal_Bool bHidden = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False ); 1157cdf0e10cSrcweir sal_Bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED() , sal_False ); 1158cdf0e10cSrcweir sal_Bool bPreview = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW() , sal_False ); 1159cdf0e10cSrcweir css::uno::Reference< css::task::XStatusIndicator > xProgress = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >()); 1160cdf0e10cSrcweir 1161cdf0e10cSrcweir if (!bHidden && !bMinimized && !bPreview && !xProgress.is()) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir // Note: its an optional interface! 1164cdf0e10cSrcweir css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY); 1165cdf0e10cSrcweir if (xProgressFactory.is()) 1166cdf0e10cSrcweir { 1167cdf0e10cSrcweir xProgress = xProgressFactory->createStatusIndicator(); 1168cdf0e10cSrcweir if (xProgress.is()) 1169cdf0e10cSrcweir m_lMediaDescriptor[::comphelper::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress; 1170cdf0e10cSrcweir } 1171cdf0e10cSrcweir } 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir // convert media descriptor and URL to right format for later interface call! 1174cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lDescriptor; 1175cdf0e10cSrcweir m_lMediaDescriptor >> lDescriptor; 1176cdf0e10cSrcweir ::rtl::OUString sURL = m_aURL.Complete; 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir // try to locate any interested frame loader 1179cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xLoader = impl_searchLoader(); 1180cdf0e10cSrcweir css::uno::Reference< css::frame::XFrameLoader > xAsyncLoader(xLoader, css::uno::UNO_QUERY); 1181cdf0e10cSrcweir css::uno::Reference< css::frame::XSynchronousFrameLoader > xSyncLoader (xLoader, css::uno::UNO_QUERY); 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir if (xAsyncLoader.is()) 1184cdf0e10cSrcweir { 1185cdf0e10cSrcweir // SAFE -> ----------------------------------- 1186cdf0e10cSrcweir aWriteLock.lock(); 1187cdf0e10cSrcweir m_xAsynchronousJob = xAsyncLoader; 1188cdf0e10cSrcweir m_pCheck = this; 1189cdf0e10cSrcweir LoadEnvListener* pListener = new LoadEnvListener(m_pCheck, this); 1190cdf0e10cSrcweir aWriteLock.unlock(); 1191cdf0e10cSrcweir // <- SAFE ----------------------------------- 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir css::uno::Reference< css::frame::XLoadEventListener > xListener(static_cast< css::frame::XLoadEventListener* >(pListener), css::uno::UNO_QUERY); 1194cdf0e10cSrcweir xAsyncLoader->load(xTargetFrame, sURL, lDescriptor, xListener); 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir return sal_True; 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir else 1199cdf0e10cSrcweir if (xSyncLoader.is()) 1200cdf0e10cSrcweir { 1201cdf0e10cSrcweir sal_Bool bResult = xSyncLoader->load(lDescriptor, xTargetFrame); 1202cdf0e10cSrcweir // react for the result here, so the outside waiting 1203cdf0e10cSrcweir // code can ask for it later. 1204cdf0e10cSrcweir impl_setResult(bResult); 1205cdf0e10cSrcweir // But the return value indicates a valid started(!) operation. 1206cdf0e10cSrcweir // And thats true everxtimes, we reach this line :-) 1207cdf0e10cSrcweir return sal_True; 1208cdf0e10cSrcweir } 1209cdf0e10cSrcweir 1210cdf0e10cSrcweir aWriteLock.unlock(); 1211cdf0e10cSrcweir // <- SAFE 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir return sal_False; 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir /*----------------------------------------------- 1217cdf0e10cSrcweir 06.02.2004 14:40 1218cdf0e10cSrcweir -----------------------------------------------*/ 1219cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > LoadEnv::impl_searchLoader() 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir // SAFE -> ----------------------------------- 1222cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir // special mode to set an existing component on this frame 1225cdf0e10cSrcweir // In such case the laoder is fix. It must be the SFX based implementation, 1226cdf0e10cSrcweir // which can create a view on top of such xModel components :-) 1227cdf0e10cSrcweir if (m_eContentType == E_CAN_BE_SET) 1228cdf0e10cSrcweir { 1229cdf0e10cSrcweir try 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir return m_xSMGR->createInstance(IMPLEMENTATIONNAME_GENERICFRAMELOADER); 1232cdf0e10cSrcweir } 1233cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 1234cdf0e10cSrcweir { throw; } 1235cdf0e10cSrcweir catch(const css::uno::Exception&) 1236cdf0e10cSrcweir {} 1237cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_INVALID_ENVIRONMENT); 1238cdf0e10cSrcweir } 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir // Otherwhise ... 1241cdf0e10cSrcweir // We need this type information to locate an registered frame loader 1242cdf0e10cSrcweir // Without such information we cant work! 1243cdf0e10cSrcweir ::rtl::OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString()); 1244cdf0e10cSrcweir if (!sType.getLength()) 1245cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR); 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir // try to locate any interested frame loader 1248cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xLoaderFactory(m_xSMGR->createInstance(SERVICENAME_FRAMELOADERFACTORY), css::uno::UNO_QUERY); 1249cdf0e10cSrcweir css::uno::Reference< css::container::XContainerQuery > xQuery (xLoaderFactory , css::uno::UNO_QUERY); 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir aReadLock.unlock(); 1252cdf0e10cSrcweir // <- SAFE ----------------------------------- 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lTypesReg(1); 1255cdf0e10cSrcweir lTypesReg[0] = sType; 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lQuery(1); 1258cdf0e10cSrcweir lQuery[0].Name = ::framework::constant::FrameLoader::PROP_TYPES; 1259cdf0e10cSrcweir lQuery[0].Value <<= lTypesReg; 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xSet = xQuery->createSubSetEnumerationByProperties(lQuery); 1262cdf0e10cSrcweir while(xSet->hasMoreElements()) 1263cdf0e10cSrcweir { 1264cdf0e10cSrcweir // try everyone ... 1265cdf0e10cSrcweir // Ignore any loader, which makes trouble :-) 1266cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement()); 1267cdf0e10cSrcweir ::rtl::OUString sLoader = lLoaderProps.getUnpackedValueOrDefault(::framework::constant::FrameLoader::PROP_NAME, ::rtl::OUString()); 1268cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xLoader ; 1269cdf0e10cSrcweir try 1270cdf0e10cSrcweir { 1271cdf0e10cSrcweir xLoader = xLoaderFactory->createInstance(sLoader); 1272cdf0e10cSrcweir if (xLoader.is()) 1273cdf0e10cSrcweir return xLoader; 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 1276cdf0e10cSrcweir { throw; } 1277cdf0e10cSrcweir catch(const css::uno::Exception&) 1278cdf0e10cSrcweir { continue; } 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir return css::uno::Reference< css::uno::XInterface >(); 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir /*----------------------------------------------- 1285cdf0e10cSrcweir 24.01.2006 15:11 1286cdf0e10cSrcweir -----------------------------------------------*/ 1287cdf0e10cSrcweir void LoadEnv::impl_jumpToMark(const css::uno::Reference< css::frame::XFrame >& xFrame, 1288cdf0e10cSrcweir const css::util::URL& aURL ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir if (! aURL.Mark.getLength()) 1291cdf0e10cSrcweir return; 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xProvider(xFrame, css::uno::UNO_QUERY); 1294cdf0e10cSrcweir if (! xProvider.is()) 1295cdf0e10cSrcweir return; 1296cdf0e10cSrcweir 1297cdf0e10cSrcweir // SAFE -> 1298cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1299cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 1300cdf0e10cSrcweir aReadLock.unlock(); 1301cdf0e10cSrcweir // <- SAFE 1302cdf0e10cSrcweir 1303cdf0e10cSrcweir css::util::URL aCmd; 1304cdf0e10cSrcweir aCmd.Complete = ::rtl::OUString::createFromAscii(".uno:JumpToMark"); 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xParser(xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY_THROW); 1307cdf0e10cSrcweir xParser->parseStrict(aCmd); 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatcher = xProvider->queryDispatch(aCmd, SPECIALTARGET_SELF, 0); 1310cdf0e10cSrcweir if (! xDispatcher.is()) 1311cdf0e10cSrcweir return; 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lArgs; 1314cdf0e10cSrcweir lArgs[::rtl::OUString::createFromAscii("Bookmark")] <<= aURL.Mark; 1315cdf0e10cSrcweir xDispatcher->dispatch(aCmd, lArgs.getAsConstPropertyValueList()); 1316cdf0e10cSrcweir } 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir /*----------------------------------------------- 1319cdf0e10cSrcweir 31.07.2003 09:02 1320cdf0e10cSrcweir -----------------------------------------------*/ 1321cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded() 1322cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 1323cdf0e10cSrcweir { 1324cdf0e10cSrcweir // SAFE -> 1325cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1326cdf0e10cSrcweir 1327cdf0e10cSrcweir // such search is allowed for special requests only ... 1328cdf0e10cSrcweir // or better its not allowed for some requests in general :-) 1329cdf0e10cSrcweir if ( 1330cdf0e10cSrcweir ( ! TargetHelper::matchSpecialTarget(m_sTarget, TargetHelper::E_DEFAULT) ) || 1331cdf0e10cSrcweir (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) || 1332cdf0e10cSrcweir // (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN() , sal_False) == sal_True) || 1333cdf0e10cSrcweir (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True) 1334cdf0e10cSrcweir ) 1335cdf0e10cSrcweir { 1336cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1337cdf0e10cSrcweir } 1338cdf0e10cSrcweir 1339cdf0e10cSrcweir // check URL 1340cdf0e10cSrcweir // May its not usefull to start expensive document search, if it 1341cdf0e10cSrcweir // can fail only .. because we load from a stream or model directly! 1342cdf0e10cSrcweir if ( 1343cdf0e10cSrcweir (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM )) || 1344cdf0e10cSrcweir (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT )) 1345cdf0e10cSrcweir /*TODO should be private:factory here tested too? */ 1346cdf0e10cSrcweir ) 1347cdf0e10cSrcweir { 1348cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1349cdf0e10cSrcweir } 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir // otherwhise - iterate through the tasks of the desktop container 1352cdf0e10cSrcweir // to find out, which of them might contains the requested document 1353cdf0e10cSrcweir css::uno::Reference< css::frame::XFramesSupplier > xSupplier(m_xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY); 1354cdf0e10cSrcweir css::uno::Reference< css::container::XIndexAccess > xTaskList(xSupplier->getFrames() , css::uno::UNO_QUERY); 1355cdf0e10cSrcweir 1356cdf0e10cSrcweir if (!xTaskList.is()) 1357cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); // task list can be empty! 1358cdf0e10cSrcweir 1359cdf0e10cSrcweir // Note: To detect if a document was alrady loaded before 1360cdf0e10cSrcweir // we check URLs here only. But might the existing and the requred 1361cdf0e10cSrcweir // document has different versions! Then its URLs are the same ... 1362cdf0e10cSrcweir sal_Int16 nNewVersion = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int16)(-1)); 1363cdf0e10cSrcweir 1364cdf0e10cSrcweir // will be used to save the first hidden frame referring the searched model 1365cdf0e10cSrcweir // Normaly we are interested on visible frames ... but if there is no such visible 1366cdf0e10cSrcweir // frame we referr to any hidden frame also (but as fallback only). 1367cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xHiddenTask; 1368cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xTask; 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir sal_Int32 count = xTaskList->getCount(); 1371cdf0e10cSrcweir for (sal_Int32 i=0; i<count; ++i) 1372cdf0e10cSrcweir { 1373cdf0e10cSrcweir try 1374cdf0e10cSrcweir { 1375cdf0e10cSrcweir // locate model of task 1376cdf0e10cSrcweir // Note: Without a model there is no chance to decide if 1377cdf0e10cSrcweir // this task contains the searched document or not! 1378cdf0e10cSrcweir xTaskList->getByIndex(i) >>= xTask; 1379cdf0e10cSrcweir if (!xTask.is()) 1380cdf0e10cSrcweir continue; 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = xTask->getController(); 1383cdf0e10cSrcweir if (!xController.is()) 1384cdf0e10cSrcweir { 1385cdf0e10cSrcweir xTask.clear (); 1386cdf0e10cSrcweir continue; 1387cdf0e10cSrcweir } 1388cdf0e10cSrcweir 1389cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel = xController->getModel(); 1390cdf0e10cSrcweir if (!xModel.is()) 1391cdf0e10cSrcweir { 1392cdf0e10cSrcweir xTask.clear (); 1393cdf0e10cSrcweir continue; 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir // don't check the complete URL here. 1397cdf0e10cSrcweir // use its main part - ignore optional jumpmarks! 1398cdf0e10cSrcweir const ::rtl::OUString sURL = xModel->getURL(); 1399cdf0e10cSrcweir if (!::utl::UCBContentHelper::EqualURLs( m_aURL.Main, sURL )) 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir xTask.clear (); 1402cdf0e10cSrcweir continue; 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir 1405cdf0e10cSrcweir // get the original load arguments from the current document 1406cdf0e10cSrcweir // and decide if its realy the same then the one will be. 1407cdf0e10cSrcweir // It must be visible and must use the same file revision ... 1408cdf0e10cSrcweir // or must not have any file revision set (-1 == -1!) 1409cdf0e10cSrcweir ::comphelper::MediaDescriptor lOldDocDescriptor(xModel->getArgs()); 1410cdf0e10cSrcweir 1411cdf0e10cSrcweir if (lOldDocDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_VERSION(), (sal_Int32)(-1)) != nNewVersion) 1412cdf0e10cSrcweir { 1413cdf0e10cSrcweir xTask.clear (); 1414cdf0e10cSrcweir continue; 1415cdf0e10cSrcweir } 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir // Hidden frames are special. 1418cdf0e10cSrcweir // They will be used as "last chance" if there is no visible frame pointing to the same model. 1419cdf0e10cSrcweir // Safe the result but continue with current loop might be looking for other visible frames. 1420cdf0e10cSrcweir ::sal_Bool bIsHidden = lOldDocDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False); 1421cdf0e10cSrcweir if ( 1422cdf0e10cSrcweir ( bIsHidden ) && 1423cdf0e10cSrcweir ( ! xHiddenTask.is()) 1424cdf0e10cSrcweir ) 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir xHiddenTask = xTask; 1427cdf0e10cSrcweir xTask.clear (); 1428cdf0e10cSrcweir continue; 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir // We found a visible task pointing to the right model ... 1432cdf0e10cSrcweir // Break search. 1433cdf0e10cSrcweir break; 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 1436cdf0e10cSrcweir { throw exRun; } 1437cdf0e10cSrcweir catch(const css::uno::Exception&) 1438cdf0e10cSrcweir { continue; } 1439cdf0e10cSrcweir } 1440cdf0e10cSrcweir 1441cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xResult; 1442cdf0e10cSrcweir if (xTask.is()) 1443cdf0e10cSrcweir xResult = xTask; 1444cdf0e10cSrcweir else 1445cdf0e10cSrcweir if (xHiddenTask.is()) 1446cdf0e10cSrcweir xResult = xHiddenTask; 1447cdf0e10cSrcweir 1448cdf0e10cSrcweir if (xResult.is()) 1449cdf0e10cSrcweir { 1450cdf0e10cSrcweir // Now we are shure, that this task includes the searched document. 1451cdf0e10cSrcweir // It's time to activate it. As special feature we try to jump internaly 1452cdf0e10cSrcweir // if an optional jumpmark is given too. 1453cdf0e10cSrcweir if (m_aURL.Mark.getLength()) 1454cdf0e10cSrcweir impl_jumpToMark(xResult, m_aURL); 1455cdf0e10cSrcweir 1456cdf0e10cSrcweir // bring it to front and make sure it's visible... 1457cdf0e10cSrcweir impl_makeFrameWindowVisible(xResult->getContainerWindow(), sal_True); 1458cdf0e10cSrcweir } 1459cdf0e10cSrcweir 1460cdf0e10cSrcweir aReadLock.unlock(); 1461cdf0e10cSrcweir // <- SAFE 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir return xResult; 1464cdf0e10cSrcweir } 1465cdf0e10cSrcweir 1466cdf0e10cSrcweir /*----------------------------------------------- 1467cdf0e10cSrcweir 30.03.2004 09:12 1468cdf0e10cSrcweir -----------------------------------------------*/ 1469cdf0e10cSrcweir sal_Bool LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) const 1470cdf0e10cSrcweir { 1471cdf0e10cSrcweir css::uno::Reference< css::document::XActionLockable > xLock(xFrame, css::uno::UNO_QUERY); 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir // ? no lock interface ? 1474cdf0e10cSrcweir // Might its an external written frame implementation :-( 1475cdf0e10cSrcweir // Allowing using of it ... but it can fail if its not synchronized with our processes ! 1476cdf0e10cSrcweir if (!xLock.is()) 1477cdf0e10cSrcweir return sal_False; 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir // Otherwhise we have to look for any other existing lock. 1480cdf0e10cSrcweir return xLock->isActionLocked(); 1481cdf0e10cSrcweir } 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir /*----------------------------------------------- 1484cdf0e10cSrcweir 30.03.2004 09:12 1485cdf0e10cSrcweir -----------------------------------------------*/ 1486cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget() 1487cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 1488cdf0e10cSrcweir { 1489cdf0e10cSrcweir // SAFE -> .................................. 1490cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1491cdf0e10cSrcweir 1492cdf0e10cSrcweir // The special backing mode frame will be recycled by definition! 1493cdf0e10cSrcweir // It does'nt matter if somehwere whish to create a new view 1494cdf0e10cSrcweir // or open a new untitled document ... 1495cdf0e10cSrcweir // The only exception form that - hidden frames! 1496cdf0e10cSrcweir if (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False) == sal_True) 1497cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1498cdf0e10cSrcweir 1499cdf0e10cSrcweir css::uno::Reference< css::frame::XFramesSupplier > xSupplier(m_xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY); 1500cdf0e10cSrcweir FrameListAnalyzer aTasksAnalyzer(xSupplier, css::uno::Reference< css::frame::XFrame >(), FrameListAnalyzer::E_BACKINGCOMPONENT); 1501cdf0e10cSrcweir if (aTasksAnalyzer.m_xBackingComponent.is()) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir if (!impl_isFrameAlreadyUsedForLoading(aTasksAnalyzer.m_xBackingComponent)) 1504cdf0e10cSrcweir { 1505cdf0e10cSrcweir // bring it to front ... 1506cdf0e10cSrcweir impl_makeFrameWindowVisible(aTasksAnalyzer.m_xBackingComponent->getContainerWindow(), sal_True); 1507cdf0e10cSrcweir return aTasksAnalyzer.m_xBackingComponent; 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir 1511cdf0e10cSrcweir // These states indicates the wishing for creation of a new view in general. 1512cdf0e10cSrcweir if ( 1513cdf0e10cSrcweir (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) || 1514cdf0e10cSrcweir (m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True) 1515cdf0e10cSrcweir ) 1516cdf0e10cSrcweir { 1517cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1518cdf0e10cSrcweir } 1519cdf0e10cSrcweir 1520cdf0e10cSrcweir // On the other side some special URLs will open a new frame everytimes (expecting 1521cdf0e10cSrcweir // they can use the backing-mode frame!) 1522cdf0e10cSrcweir if ( 1523cdf0e10cSrcweir (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_FACTORY )) || 1524cdf0e10cSrcweir (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM )) || 1525cdf0e10cSrcweir (ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT )) 1526cdf0e10cSrcweir ) 1527cdf0e10cSrcweir { 1528cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1529cdf0e10cSrcweir } 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir // No backing frame! No special URL => recycle active task - if possible. 1532cdf0e10cSrcweir // Means - if it does not already contains a modified document, or 1533cdf0e10cSrcweir // use another office module. 1534cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xTask = xSupplier->getActiveFrame(); 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir // not a real error - but might a focus problem! 1537cdf0e10cSrcweir if (!xTask.is()) 1538cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1539cdf0e10cSrcweir 1540cdf0e10cSrcweir // not a real error - may its a view only 1541cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = xTask->getController(); 1542cdf0e10cSrcweir if (!xController.is()) 1543cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir // not a real error - may its a db component instead of a full feartured office document 1546cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel = xController->getModel(); 1547cdf0e10cSrcweir if (!xModel.is()) 1548cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1549cdf0e10cSrcweir 1550cdf0e10cSrcweir // get some more informations ... 1551cdf0e10cSrcweir 1552cdf0e10cSrcweir // A valid set URL means: there is already a location for this document. 1553cdf0e10cSrcweir // => it was saved there or opened from there. Such Documents can not be used here. 1554cdf0e10cSrcweir // We search for empty document ... created by a private:factory/ URL! 1555cdf0e10cSrcweir if (xModel->getURL().getLength()>0) 1556cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1557cdf0e10cSrcweir 1558cdf0e10cSrcweir // The old document must be unmodified ... 1559cdf0e10cSrcweir css::uno::Reference< css::util::XModifiable > xModified(xModel, css::uno::UNO_QUERY); 1560cdf0e10cSrcweir if (xModified->isModified()) 1561cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xTask->getContainerWindow()); 1564cdf0e10cSrcweir if (pWindow && pWindow->IsInModalMode()) 1565cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1566cdf0e10cSrcweir 1567cdf0e10cSrcweir // find out the application type of this document 1568cdf0e10cSrcweir // We can recycle only documents, which uses the same application 1569cdf0e10cSrcweir // then the new one. 1570cdf0e10cSrcweir SvtModuleOptions::EFactory eOldApp = SvtModuleOptions::ClassifyFactoryByModel(xModel); 1571cdf0e10cSrcweir SvtModuleOptions::EFactory eNewApp = SvtModuleOptions::ClassifyFactoryByURL (m_aURL.Complete, m_lMediaDescriptor.getAsConstPropertyValueList()); 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir aReadLock.unlock(); 1574cdf0e10cSrcweir // <- SAFE .................................. 1575cdf0e10cSrcweir 1576cdf0e10cSrcweir if (eOldApp != eNewApp) 1577cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir // OK this task seams to be useable for recycling 1580cdf0e10cSrcweir // But we should mark it as such - means set an action lock. 1581cdf0e10cSrcweir // Otherwhise it would be used more then ones or will be destroyed 1582cdf0e10cSrcweir // by a close() or terminate() request. 1583cdf0e10cSrcweir // But if such lock already exist ... it means this task is used for 1584cdf0e10cSrcweir // any other operation already. Don't use it then. 1585cdf0e10cSrcweir if (impl_isFrameAlreadyUsedForLoading(xTask)) 1586cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir // OK - there is a valid target frame. 1589cdf0e10cSrcweir // But may be it contains already a document. 1590cdf0e10cSrcweir // Then we have to ask it, if it allows recylcing of this frame .-) 1591cdf0e10cSrcweir sal_Bool bReactivateOldControllerOnError = sal_False; 1592cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xOldDoc = xTask->getController(); 1593cdf0e10cSrcweir if (xOldDoc.is()) 1594cdf0e10cSrcweir { 1595cdf0e10cSrcweir bReactivateOldControllerOnError = xOldDoc->suspend(sal_True); 1596cdf0e10cSrcweir if (! bReactivateOldControllerOnError) 1597cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1598cdf0e10cSrcweir } 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir // SAFE -> .................................. 1601cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1602cdf0e10cSrcweir 1603cdf0e10cSrcweir css::uno::Reference< css::document::XActionLockable > xLock(xTask, css::uno::UNO_QUERY); 1604cdf0e10cSrcweir if (!m_aTargetLock.setResource(xLock)) 1605cdf0e10cSrcweir return css::uno::Reference< css::frame::XFrame >(); 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir m_bReactivateControllerOnError = bReactivateOldControllerOnError; 1608cdf0e10cSrcweir aWriteLock.unlock(); 1609cdf0e10cSrcweir // <- SAFE .................................. 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir // bring it to front ... 1612cdf0e10cSrcweir impl_makeFrameWindowVisible(xTask->getContainerWindow(), sal_True); 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir return xTask; 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir /*----------------------------------------------- 1618cdf0e10cSrcweir 15.08.2003 12:39 1619cdf0e10cSrcweir -----------------------------------------------*/ 1620cdf0e10cSrcweir void LoadEnv::impl_reactForLoadingState() 1621cdf0e10cSrcweir throw(LoadEnvException, css::uno::RuntimeException) 1622cdf0e10cSrcweir { 1623cdf0e10cSrcweir /*TODO reset action locks */ 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir // SAFE -> ---------------------------------- 1626cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1627cdf0e10cSrcweir 1628cdf0e10cSrcweir if (m_bLoaded) 1629cdf0e10cSrcweir { 1630cdf0e10cSrcweir // Bring the new loaded document to front (if allowed!). 1631cdf0e10cSrcweir // Note: We show new created frames here only. 1632cdf0e10cSrcweir // We dont hide already visible frames here ... 1633cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xWindow = m_xTargetFrame->getContainerWindow(); 1634cdf0e10cSrcweir sal_Bool bHidden = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_HIDDEN(), sal_False); 1635cdf0e10cSrcweir sal_Bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_MINIMIZED(), sal_False); 1636cdf0e10cSrcweir 1637cdf0e10cSrcweir if (bMinimized) 1638cdf0e10cSrcweir { 1639cdf0e10cSrcweir ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex()); 1640cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xWindow); 1641cdf0e10cSrcweir // check for system window is neccessary to guarantee correct pointer cast! 1642cdf0e10cSrcweir if (pWindow && pWindow->IsSystemWindow()) 1643cdf0e10cSrcweir ((WorkWindow*)pWindow)->Minimize(); 1644cdf0e10cSrcweir } 1645cdf0e10cSrcweir else 1646cdf0e10cSrcweir if (!bHidden) 1647cdf0e10cSrcweir { 1648cdf0e10cSrcweir // show frame ... if it's not still visible ... 1649cdf0e10cSrcweir // But do nothing if it's already visible! 1650cdf0e10cSrcweir impl_makeFrameWindowVisible(xWindow, sal_False); 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir // Note: Only if an existing property "FrameName" is given by this media descriptor, 1654cdf0e10cSrcweir // it should be used. Otherwhise we should do nothing. May be the outside code has already 1655cdf0e10cSrcweir // set a frame name on the target! 1656cdf0e10cSrcweir ::comphelper::MediaDescriptor::const_iterator pFrameName = m_lMediaDescriptor.find(::comphelper::MediaDescriptor::PROP_FRAMENAME()); 1657cdf0e10cSrcweir if (pFrameName != m_lMediaDescriptor.end()) 1658cdf0e10cSrcweir { 1659cdf0e10cSrcweir ::rtl::OUString sFrameName; 1660cdf0e10cSrcweir pFrameName->second >>= sFrameName; 1661cdf0e10cSrcweir // Check the name again. e.g. "_default" isnt allowed. 1662cdf0e10cSrcweir // On the other side "_beamer" is a valid name :-) 1663cdf0e10cSrcweir if (TargetHelper::isValidNameForFrame(sFrameName)) 1664cdf0e10cSrcweir m_xTargetFrame->setName(sFrameName); 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir } 1667cdf0e10cSrcweir else if (m_bReactivateControllerOnError) 1668cdf0e10cSrcweir { 1669cdf0e10cSrcweir // Try to reactivate the old document (if any exists!) 1670cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xOldDoc = m_xTargetFrame->getController(); 1671cdf0e10cSrcweir // clear does not depend from reactivation state of a might existing old document! 1672cdf0e10cSrcweir // We must make shure, that a might following getTargetComponent() call does not return 1673cdf0e10cSrcweir // the old document! 1674cdf0e10cSrcweir m_xTargetFrame.clear(); 1675cdf0e10cSrcweir if (xOldDoc.is()) 1676cdf0e10cSrcweir { 1677cdf0e10cSrcweir sal_Bool bReactivated = xOldDoc->suspend(sal_False); 1678cdf0e10cSrcweir if (!bReactivated) 1679cdf0e10cSrcweir throw LoadEnvException(LoadEnvException::ID_COULD_NOT_REACTIVATE_CONTROLLER); 1680cdf0e10cSrcweir m_bReactivateControllerOnError = sal_False; 1681cdf0e10cSrcweir } 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir else if (m_bCloseFrameOnError) 1684cdf0e10cSrcweir { 1685cdf0e10cSrcweir // close empty frames 1686cdf0e10cSrcweir css::uno::Reference< css::util::XCloseable > xCloseable (m_xTargetFrame, css::uno::UNO_QUERY); 1687cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xDisposable(m_xTargetFrame, css::uno::UNO_QUERY); 1688cdf0e10cSrcweir 1689cdf0e10cSrcweir try 1690cdf0e10cSrcweir { 1691cdf0e10cSrcweir if (xCloseable.is()) 1692cdf0e10cSrcweir xCloseable->close(sal_True); 1693cdf0e10cSrcweir else 1694cdf0e10cSrcweir if (xDisposable.is()) 1695cdf0e10cSrcweir xDisposable->dispose(); 1696cdf0e10cSrcweir } 1697cdf0e10cSrcweir catch(const css::util::CloseVetoException&) 1698cdf0e10cSrcweir {} 1699cdf0e10cSrcweir catch(const css::lang::DisposedException&) 1700cdf0e10cSrcweir {} 1701cdf0e10cSrcweir m_xTargetFrame.clear(); 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir 1704cdf0e10cSrcweir // This max force an implicit closing of our target frame ... 1705cdf0e10cSrcweir // e.g. in case close(sal_True) was called before and the frame 1706cdf0e10cSrcweir // kill itself if our external use-lock is released here! 1707cdf0e10cSrcweir // Thats why we releas this lock AFTER ALL OPERATIONS on this frame 1708cdf0e10cSrcweir // are finished. The frame itslef must handle then 1709cdf0e10cSrcweir // this situation gracefully. 1710cdf0e10cSrcweir m_aTargetLock.freeResource(); 1711cdf0e10cSrcweir 1712cdf0e10cSrcweir // Last but not least :-) 1713cdf0e10cSrcweir // We have to clear the current media descriptor. 1714cdf0e10cSrcweir // Otherwhise it hold a might existing stream open! 1715cdf0e10cSrcweir m_lMediaDescriptor.clear(); 1716cdf0e10cSrcweir 1717cdf0e10cSrcweir css::uno::Any aRequest; 1718cdf0e10cSrcweir bool bThrow = false; 1719cdf0e10cSrcweir if ( !m_bLoaded && m_pQuietInteraction && m_pQuietInteraction->wasUsed() ) 1720cdf0e10cSrcweir { 1721cdf0e10cSrcweir aRequest = m_pQuietInteraction->getRequest(); 1722cdf0e10cSrcweir m_pQuietInteraction->release(); 1723cdf0e10cSrcweir m_pQuietInteraction = 0; 1724cdf0e10cSrcweir bThrow = true; 1725cdf0e10cSrcweir } 1726cdf0e10cSrcweir 1727cdf0e10cSrcweir aReadLock.unlock(); 1728cdf0e10cSrcweir 1729cdf0e10cSrcweir if (bThrow) 1730cdf0e10cSrcweir { 1731cdf0e10cSrcweir if ( aRequest.isExtractableTo( ::cppu::UnoType< css::uno::Exception >::get() ) ) 1732cdf0e10cSrcweir throw LoadEnvException( LoadEnvException::ID_GENERAL_ERROR, aRequest ); 1733cdf0e10cSrcweir } 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir // <- SAFE ---------------------------------- 1736cdf0e10cSrcweir } 1737cdf0e10cSrcweir 1738cdf0e10cSrcweir /*----------------------------------------------- 1739cdf0e10cSrcweir 16.01.2005 13:04 1740cdf0e10cSrcweir -----------------------------------------------*/ 1741cdf0e10cSrcweir void LoadEnv::impl_makeFrameWindowVisible(const css::uno::Reference< css::awt::XWindow >& xWindow , 1742cdf0e10cSrcweir sal_Bool bForceToFront) 1743cdf0e10cSrcweir { 1744cdf0e10cSrcweir // SAFE -> ---------------------------------- 1745cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1746cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xSMGR.get(), css::uno::UNO_QUERY ); 1747cdf0e10cSrcweir aReadLock.unlock(); 1748cdf0e10cSrcweir // <- SAFE ---------------------------------- 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex()); 1751cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xWindow); 1752cdf0e10cSrcweir if ( pWindow ) 1753cdf0e10cSrcweir { 1754cdf0e10cSrcweir bool bForceFrontAndFocus(false); 1755cdf0e10cSrcweir css::uno::Any a = ::comphelper::ConfigurationHelper::readDirectKey( 1756cdf0e10cSrcweir xSMGR, 1757cdf0e10cSrcweir ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/View"), 1758cdf0e10cSrcweir ::rtl::OUString::createFromAscii("NewDocumentHandling"), 1759cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ForceFocusAndToFront"), 1760cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY); 1761cdf0e10cSrcweir a >>= bForceFrontAndFocus; 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir if( pWindow->IsVisible() && (bForceFrontAndFocus || bForceToFront) ) 1764cdf0e10cSrcweir pWindow->ToTop(); 1765cdf0e10cSrcweir else 1766cdf0e10cSrcweir pWindow->Show(sal_True, (bForceFrontAndFocus || bForceToFront) ? SHOW_FOREGROUNDTASK : 0 ); 1767cdf0e10cSrcweir } 1768cdf0e10cSrcweir 1769cdf0e10cSrcweir /* #i19976# 1770cdf0e10cSrcweir We tried to prevent a toFront() call in case the user putted the 1771cdf0e10cSrcweir loading document into the background .. 1772cdf0e10cSrcweir But we had several errors trying that. So we decided to 1773cdf0e10cSrcweir rollback these changes and bring the new loaded document to front hardly ! 1774cdf0e10cSrcweir 1775cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow2 > xWindow2(xWindow, css::uno::UNO_QUERY); 1776cdf0e10cSrcweir 1777cdf0e10cSrcweir sal_Bool bIsVisible = sal_False; 1778cdf0e10cSrcweir if (xWindow2.is()) 1779cdf0e10cSrcweir bIsVisible = xWindow2->isVisible(); // TODO is parent visible too ? .-) 1780cdf0e10cSrcweir 1781cdf0e10cSrcweir if (!bIsVisible) 1782cdf0e10cSrcweir { 1783cdf0e10cSrcweir xWindow->setVisible(sal_True); 1784cdf0e10cSrcweir bForceToFront = sal_True; 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir if ( 1788cdf0e10cSrcweir (bForceToFront ) && 1789cdf0e10cSrcweir (xTopWindow.is()) 1790cdf0e10cSrcweir ) 1791cdf0e10cSrcweir { 1792cdf0e10cSrcweir xTopWindow->toFront(); 1793cdf0e10cSrcweir } 1794cdf0e10cSrcweir */ 1795cdf0e10cSrcweir } 1796cdf0e10cSrcweir 1797cdf0e10cSrcweir /*----------------------------------------------- 1798cdf0e10cSrcweir 15.03.2005 11:12 1799cdf0e10cSrcweir -----------------------------------------------*/ 1800cdf0e10cSrcweir void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow) 1801cdf0e10cSrcweir { 1802cdf0e10cSrcweir static ::rtl::OUString PACKAGE_SETUP_MODULES = ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Office/Factories"); 1803cdf0e10cSrcweir 1804cdf0e10cSrcweir // no window -> action not possible 1805cdf0e10cSrcweir if (!xWindow.is()) 1806cdf0e10cSrcweir return; 1807cdf0e10cSrcweir 1808cdf0e10cSrcweir // window already visible -> do nothing! If we use a "recycle frame" for loading ... 1809cdf0e10cSrcweir // the current position and size must be used. 1810cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow2 > xVisibleCheck(xWindow, css::uno::UNO_QUERY); 1811cdf0e10cSrcweir if ( 1812cdf0e10cSrcweir (xVisibleCheck.is() ) && 1813cdf0e10cSrcweir (xVisibleCheck->isVisible()) 1814cdf0e10cSrcweir ) 1815cdf0e10cSrcweir return; 1816cdf0e10cSrcweir 1817cdf0e10cSrcweir // SOLAR SAFE -> 1818cdf0e10cSrcweir ::vos::OClearableGuard aSolarLock1(Application::GetSolarMutex()); 1819cdf0e10cSrcweir 1820cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xWindow); 1821cdf0e10cSrcweir sal_Bool bSystemWindow = pWindow->IsSystemWindow(); 1822cdf0e10cSrcweir sal_Bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW); 1823cdf0e10cSrcweir 1824cdf0e10cSrcweir if (!bSystemWindow && !bWorkWindow) 1825cdf0e10cSrcweir return; 1826cdf0e10cSrcweir 1827cdf0e10cSrcweir // dont overwrite this special state! 1828cdf0e10cSrcweir WorkWindow* pWorkWindow = (WorkWindow*)pWindow; 1829cdf0e10cSrcweir if (pWorkWindow->IsMinimized()) 1830cdf0e10cSrcweir return; 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir aSolarLock1.clear(); 1833cdf0e10cSrcweir // <- SOLAR SAFE 1834cdf0e10cSrcweir 1835cdf0e10cSrcweir // SAFE -> 1836cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1837cdf0e10cSrcweir 1838cdf0e10cSrcweir // no filter -> no module -> no persistent window state 1839cdf0e10cSrcweir ::rtl::OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault( 1840cdf0e10cSrcweir ::comphelper::MediaDescriptor::PROP_FILTERNAME(), 1841cdf0e10cSrcweir ::rtl::OUString()); 1842cdf0e10cSrcweir if (!sFilter.getLength()) 1843cdf0e10cSrcweir return; 1844cdf0e10cSrcweir 1845cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir aReadLock.unlock(); 1848cdf0e10cSrcweir // <- SAFE 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir try 1851cdf0e10cSrcweir { 1852cdf0e10cSrcweir // retrieve the module name from the filter configuration 1853cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xFilterCfg( 1854cdf0e10cSrcweir xSMGR->createInstance(SERVICENAME_FILTERFACTORY), 1855cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 1856cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lProps (xFilterCfg->getByName(sFilter)); 1857cdf0e10cSrcweir ::rtl::OUString sModule = lProps.getUnpackedValueOrDefault(FILTER_PROPNAME_DOCUMENTSERVICE, ::rtl::OUString()); 1858cdf0e10cSrcweir 1859cdf0e10cSrcweir // get access to the configuration of this office module 1860cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModuleCfg(::comphelper::ConfigurationHelper::openConfig( 1861cdf0e10cSrcweir xSMGR, 1862cdf0e10cSrcweir PACKAGE_SETUP_MODULES, 1863cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY), 1864cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 1865cdf0e10cSrcweir 1866cdf0e10cSrcweir // read window state from the configuration 1867cdf0e10cSrcweir // and apply it on the window. 1868cdf0e10cSrcweir // Do nothing, if no configuration entry exists! 1869cdf0e10cSrcweir ::rtl::OUString sWindowState ; 1870cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readRelativeKey(xModuleCfg, sModule, OFFICEFACTORY_PROPNAME_WINDOWATTRIBUTES) >>= sWindowState; 1871cdf0e10cSrcweir if (sWindowState.getLength()) 1872cdf0e10cSrcweir { 1873cdf0e10cSrcweir // SOLAR SAFE -> 1874cdf0e10cSrcweir ::vos::OClearableGuard aSolarLock2(Application::GetSolarMutex()); 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir // We have to retrieve the window pointer again. Because nobody can guarantee 1877cdf0e10cSrcweir // that the XWindow was not disposed inbetween .-) 1878cdf0e10cSrcweir // But if we get a valid pointer we can be sure, that it's the system window pointer 1879cdf0e10cSrcweir // we already checked and used before. Because nobody recylce the same uno reference for 1880cdf0e10cSrcweir // a new internal c++ implementation ... hopefully .-)) 1881cdf0e10cSrcweir Window* pWindowCheck = VCLUnoHelper::GetWindow(xWindow); 1882cdf0e10cSrcweir if (! pWindowCheck) 1883cdf0e10cSrcweir return; 1884cdf0e10cSrcweir 1885cdf0e10cSrcweir SystemWindow* pSystemWindow = (SystemWindow*)pWindowCheck; 1886cdf0e10cSrcweir pSystemWindow->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8)); 1887cdf0e10cSrcweir 1888cdf0e10cSrcweir aSolarLock2.clear(); 1889cdf0e10cSrcweir // <- SOLAR SAFE 1890cdf0e10cSrcweir } 1891cdf0e10cSrcweir } 1892cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 1893cdf0e10cSrcweir { throw exRun; } 1894cdf0e10cSrcweir catch(const css::uno::Exception&) 1895cdf0e10cSrcweir {} 1896cdf0e10cSrcweir } 1897cdf0e10cSrcweir 1898cdf0e10cSrcweir } // namespace framework 1899cdf0e10cSrcweir 1900