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