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