2012-11-29 21:26:09 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2004-01-28 13:37:23 +00:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2004-01-28 13:37:23 +00:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2004-01-28 13:37:23 +00:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 13:05:26 +00:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <loadenv/loadenv.hxx>
|
|
|
|
|
|
|
|
#include <loadenv/targethelper.hxx>
|
2010-10-29 15:36:30 +02:00
|
|
|
#include <framework/framelistanalyzer.hxx>
|
2005-02-02 12:54:18 +00:00
|
|
|
|
2009-09-18 10:15:03 +00:00
|
|
|
#include <interaction/quietinteraction.hxx>
|
2005-03-23 15:15:20 +00:00
|
|
|
#include <properties.h>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <protocols.h>
|
|
|
|
#include <services.h>
|
2010-07-13 14:36:24 +02:00
|
|
|
#include <comphelper/interaction.hxx>
|
2010-04-19 19:05:02 +02:00
|
|
|
#include <framework/interaction.hxx>
|
2012-12-04 07:50:20 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/configuration.hxx>
|
|
|
|
#include "officecfg/Office/Common.hxx"
|
2005-11-11 11:06:12 +00:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <com/sun/star/awt/XWindow.hpp>
|
2005-03-03 23:14:34 +00:00
|
|
|
#include <com/sun/star/awt/XWindow2.hpp>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <com/sun/star/awt/XTopWindow.hpp>
|
2013-05-30 15:02:11 +02:00
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XContainerQuery.hpp>
|
|
|
|
#include <com/sun/star/container/XEnumeration.hpp>
|
|
|
|
#include <com/sun/star/document/MacroExecMode.hpp>
|
|
|
|
#include <com/sun/star/document/XTypeDetection.hpp>
|
|
|
|
#include <com/sun/star/document/XActionLockable.hpp>
|
|
|
|
#include <com/sun/star/document/UpdateDocMode.hpp>
|
2012-12-14 12:58:00 +02:00
|
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
2013-05-29 08:09:33 +02:00
|
|
|
#include <com/sun/star/frame/OfficeFrameLoader.hpp>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <com/sun/star/frame/XModel.hpp>
|
|
|
|
#include <com/sun/star/frame/XFrameLoader.hpp>
|
|
|
|
#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
|
|
|
|
#include <com/sun/star/frame/XNotifyingDispatch.hpp>
|
2013-05-30 15:02:11 +02:00
|
|
|
#include <com/sun/star/frame/FrameLoaderFactory.hpp>
|
|
|
|
#include <com/sun/star/frame/ContentHandlerFactory.hpp>
|
|
|
|
#include <com/sun/star/frame/DispatchResultState.hpp>
|
|
|
|
#include <com/sun/star/frame/FrameSearchFlag.hpp>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <com/sun/star/frame/XDispatchProvider.hpp>
|
2013-05-30 15:02:11 +02:00
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/task/XInteractionHandler.hpp>
|
2013-05-30 15:02:11 +02:00
|
|
|
#include <com/sun/star/task/ErrorCodeRequest.hpp>
|
|
|
|
#include <com/sun/star/task/InteractionHandler.hpp>
|
|
|
|
#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
|
|
|
|
#include <com/sun/star/task/XStatusIndicator.hpp>
|
|
|
|
#include <com/sun/star/uno/RuntimeException.hpp>
|
|
|
|
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
|
|
|
|
#include <com/sun/star/util/URLTransformer.hpp>
|
|
|
|
#include <com/sun/star/util/XURLTransformer.hpp>
|
|
|
|
#include <com/sun/star/util/XCloseable.hpp>
|
|
|
|
#include <com/sun/star/util/XModifiable.hpp>
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2004-07-23 10:08:28 +00:00
|
|
|
#include <vcl/window.hxx>
|
|
|
|
#include <vcl/wrkwin.hxx>
|
|
|
|
#include <vcl/syswin.hxx>
|
|
|
|
|
2013-06-28 04:38:06 +02:00
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/moduleoptions.hxx>
|
2005-11-11 11:06:12 +00:00
|
|
|
#include <svtools/sfxecode.hxx>
|
2010-08-09 10:47:38 +02:00
|
|
|
#include <unotools/ucbhelper.hxx>
|
2005-03-23 15:15:20 +00:00
|
|
|
#include <comphelper/configurationhelper.hxx>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2014-05-10 18:15:21 +02:00
|
|
|
#include <rtl/bootstrap.hxx>
|
2004-01-28 13:37:23 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
|
2013-09-18 21:35:50 -04:00
|
|
|
#include <config_orcus.h>
|
|
|
|
|
2012-03-31 15:54:07 +01:00
|
|
|
const char PROP_TYPES[] = "Types";
|
|
|
|
const char PROP_NAME[] = "Name";
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
namespace framework {
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
using namespace com::sun::star;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2014-03-20 10:39:33 +01:00
|
|
|
class LoadEnvListener : public ::cppu::WeakImplHelper2< css::frame::XLoadEventListener ,
|
2004-01-28 13:37:23 +00:00
|
|
|
css::frame::XDispatchResultListener >
|
|
|
|
{
|
|
|
|
private:
|
2014-03-20 10:39:33 +01:00
|
|
|
osl::Mutex m_mutex;
|
2011-08-08 11:45:24 +01:00
|
|
|
bool m_bWaitingResult;
|
2004-01-28 13:37:23 +00:00
|
|
|
LoadEnv* m_pLoadEnv;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-08-08 11:45:24 +01:00
|
|
|
LoadEnvListener(LoadEnv* pLoadEnv)
|
|
|
|
: m_bWaitingResult(true)
|
|
|
|
, m_pLoadEnv(pLoadEnv)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// frame.XLoadEventListener
|
|
|
|
virtual void SAL_CALL loadFinished(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
|
2014-03-26 16:37:00 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
virtual void SAL_CALL loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >& xLoader)
|
2014-03-26 16:37:00 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// frame.XDispatchResultListener
|
|
|
|
virtual void SAL_CALL dispatchFinished(const css::frame::DispatchResultEvent& aEvent)
|
2014-03-26 16:37:00 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// lang.XEventListener
|
|
|
|
virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
|
2014-03-26 16:37:00 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2004-01-28 13:37:23 +00:00
|
|
|
};
|
|
|
|
|
2013-05-21 17:38:02 +02:00
|
|
|
LoadEnv::LoadEnv(const css::uno::Reference< css::uno::XComponentContext >& xContext)
|
2004-01-28 13:37:23 +00:00
|
|
|
throw(LoadEnvException, css::uno::RuntimeException)
|
2014-04-23 13:34:44 +01:00
|
|
|
: m_xContext(xContext)
|
|
|
|
, m_nSearchFlags(0)
|
|
|
|
, m_eFeature(E_NO_FEATURE)
|
|
|
|
, m_eContentType(E_UNSUPPORTED_CONTENT)
|
|
|
|
, m_bCloseFrameOnError(false)
|
|
|
|
, m_bReactivateControllerOnError(false)
|
2014-05-11 08:56:07 +03:00
|
|
|
, m_bLoaded( false )
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadEnv::~LoadEnv()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::lang::XComponent > LoadEnv::loadComponentFromURL(const css::uno::Reference< css::frame::XComponentLoader >& xLoader,
|
2013-05-21 17:38:02 +02:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xContext ,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sURL ,
|
|
|
|
const OUString& sTarget,
|
2004-01-28 13:37:23 +00:00
|
|
|
sal_Int32 nFlags ,
|
|
|
|
const css::uno::Sequence< css::beans::PropertyValue >& lArgs )
|
|
|
|
throw(css::lang::IllegalArgumentException,
|
|
|
|
css::io::IOException ,
|
|
|
|
css::uno::RuntimeException )
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::lang::XComponent > xComponent;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-05-21 17:38:02 +02:00
|
|
|
LoadEnv aEnv(xContext);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
aEnv.initializeLoading(sURL,
|
|
|
|
lArgs,
|
|
|
|
css::uno::Reference< css::frame::XFrame >(xLoader, css::uno::UNO_QUERY),
|
|
|
|
sTarget,
|
|
|
|
nFlags,
|
|
|
|
LoadEnv::E_NO_FEATURE);
|
|
|
|
aEnv.startLoading();
|
|
|
|
aEnv.waitWhileLoading(); // wait for ever!
|
|
|
|
|
|
|
|
xComponent = aEnv.getTargetComponent();
|
|
|
|
}
|
|
|
|
catch(const LoadEnvException& ex)
|
|
|
|
{
|
|
|
|
switch(ex.m_nID)
|
|
|
|
{
|
|
|
|
case LoadEnvException::ID_INVALID_MEDIADESCRIPTOR:
|
2011-12-20 10:00:36 +00:00
|
|
|
throw css::lang::IllegalArgumentException(
|
2013-02-05 13:19:24 -05:00
|
|
|
"Optional list of arguments seem to be corrupted.", xLoader, 4);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2004-04-21 12:55:35 +00:00
|
|
|
case LoadEnvException::ID_UNSUPPORTED_CONTENT:
|
2013-08-20 17:58:20 +02:00
|
|
|
throw css::lang::IllegalArgumentException(
|
2014-07-01 15:45:52 +02:00
|
|
|
"Unsupported URL <" + sURL + ">: \"" + ex.m_sMessage + "\"",
|
2011-09-12 10:32:23 +02:00
|
|
|
xLoader, 1);
|
2004-04-21 12:55:35 +00:00
|
|
|
|
2011-12-20 10:00:36 +00:00
|
|
|
default:
|
2013-08-20 17:58:20 +02:00
|
|
|
SAL_WARN(
|
|
|
|
"fwk.loadenv",
|
|
|
|
"caught LoadEnvException " << +ex.m_nID << " \""
|
|
|
|
<< ex.m_sMessage << "\""
|
|
|
|
<< (ex.m_exOriginal.has<css::uno::Exception>()
|
|
|
|
? (", " + ex.m_exOriginal.getValueTypeName() + " \""
|
|
|
|
+ (ex.m_exOriginal.get<css::uno::Exception>().
|
|
|
|
Message)
|
|
|
|
+ "\"")
|
|
|
|
: OUString())
|
|
|
|
<< " while loading <" << sURL << ">");
|
2011-12-20 10:00:36 +00:00
|
|
|
xComponent.clear();
|
|
|
|
break;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return xComponent;
|
|
|
|
}
|
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor impl_mergeMediaDescriptorWithMightExistingModelArgs(const css::uno::Sequence< css::beans::PropertyValue >& lOutsideDescriptor)
|
2008-02-12 12:11:06 +00:00
|
|
|
{
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor lDescriptor(lOutsideDescriptor);
|
2008-02-12 12:11:06 +00:00
|
|
|
css::uno::Reference< css::frame::XModel > xModel = lDescriptor.getUnpackedValueOrDefault(
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::PROP_MODEL (),
|
2008-02-12 12:11:06 +00:00
|
|
|
css::uno::Reference< css::frame::XModel > ());
|
|
|
|
if (xModel.is ())
|
|
|
|
{
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor lModelDescriptor(xModel->getArgs());
|
|
|
|
utl::MediaDescriptor::iterator pIt = lModelDescriptor.find( utl::MediaDescriptor::PROP_MACROEXECUTIONMODE() );
|
2008-02-26 06:50:37 +00:00
|
|
|
if ( pIt != lModelDescriptor.end() )
|
2013-11-13 08:52:41 +01:00
|
|
|
lDescriptor[utl::MediaDescriptor::PROP_MACROEXECUTIONMODE()] = pIt->second;
|
2008-02-12 12:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lDescriptor;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void LoadEnv::initializeLoading(const OUString& sURL ,
|
2004-01-28 13:37:23 +00:00
|
|
|
const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor,
|
|
|
|
const css::uno::Reference< css::frame::XFrame >& xBaseFrame ,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sTarget ,
|
2004-01-28 13:37:23 +00:00
|
|
|
sal_Int32 nSearchFlags ,
|
|
|
|
EFeature eFeature , // => use default ...
|
|
|
|
EContentType eContentType ) // => use default ...
|
|
|
|
{
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// Handle still running processes!
|
|
|
|
if (m_xAsynchronousJob.is())
|
|
|
|
throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
|
|
|
|
|
|
|
|
// take over all new parameters.
|
|
|
|
m_xTargetFrame.clear();
|
2014-04-06 19:36:08 +03:00
|
|
|
m_xBaseFrame = xBaseFrame;
|
2008-02-12 12:11:06 +00:00
|
|
|
m_lMediaDescriptor = impl_mergeMediaDescriptorWithMightExistingModelArgs(lMediaDescriptor);
|
2014-04-06 19:36:08 +03:00
|
|
|
m_sTarget = sTarget;
|
|
|
|
m_nSearchFlags = nSearchFlags;
|
|
|
|
m_eFeature = eFeature;
|
|
|
|
m_eContentType = eContentType;
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bCloseFrameOnError = false;
|
|
|
|
m_bReactivateControllerOnError = false;
|
|
|
|
m_bLoaded = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2011-11-13 23:44:40 +01:00
|
|
|
// try to find out, if its really a content, which can be loaded or must be "handled"
|
2004-01-28 13:37:23 +00:00
|
|
|
// We use a default value for this in-parameter. Then we have to start a complex check method
|
2013-09-26 10:02:26 +02:00
|
|
|
// internally. But if this check was already done outside it can be suppressed to perform
|
2004-01-28 13:37:23 +00:00
|
|
|
// the load request. We take over the result then!
|
|
|
|
if (m_eContentType == E_UNSUPPORTED_CONTENT)
|
|
|
|
{
|
|
|
|
m_eContentType = LoadEnv::classifyContent(sURL, lMediaDescriptor);
|
|
|
|
if (m_eContentType == E_UNSUPPORTED_CONTENT)
|
2013-08-20 17:58:20 +02:00
|
|
|
throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT, "from LoadEnv::initializeLoading");
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make URL part of the MediaDescriptor
|
2011-11-13 23:44:40 +01:00
|
|
|
// It doesn't mater, if it is already an item of it.
|
2004-01-28 13:37:23 +00:00
|
|
|
// It must be the same value ... so we can overwrite it :-)
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_URL()] <<= sURL;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// parse it - because some following code require that
|
|
|
|
m_aURL.Complete = sURL;
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::util::XURLTransformer > xParser(css::util::URLTransformer::create(m_xContext));
|
2004-01-28 13:37:23 +00:00
|
|
|
xParser->parseStrict(m_aURL);
|
|
|
|
|
2004-06-10 12:21:50 +00:00
|
|
|
// BTW: Split URL and JumpMark ...
|
|
|
|
// Because such mark is an explicit value of the media descriptor!
|
2011-12-26 14:20:50 -02:00
|
|
|
if (!m_aURL.Mark.isEmpty())
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_JUMPMARK()] <<= m_aURL.Mark;
|
2004-06-10 12:21:50 +00:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// By the way: remove the old and deprecated value "FileName" from the descriptor!
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::iterator pIt = m_lMediaDescriptor.find(utl::MediaDescriptor::PROP_FILENAME());
|
2004-01-28 13:37:23 +00:00
|
|
|
if (pIt != m_lMediaDescriptor.end())
|
|
|
|
m_lMediaDescriptor.erase(pIt);
|
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// patch the MediaDescriptor, so it fulfil the outside requirements
|
2011-11-13 23:44:40 +01:00
|
|
|
// Means especially items like e.g. UI InteractionHandler, Status Indicator,
|
2013-09-26 10:02:26 +02:00
|
|
|
// MacroExecutionMode, etc.
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
/*TODO progress is bound to a frame ... How can we set it here? */
|
|
|
|
|
2010-01-22 22:46:39 +01:00
|
|
|
// UI mode
|
|
|
|
const bool bUIMode =
|
|
|
|
( ( m_eFeature & E_WORK_WITH_UI ) == E_WORK_WITH_UI ) &&
|
2013-11-13 08:52:41 +01:00
|
|
|
( m_lMediaDescriptor.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_HIDDEN() , sal_False ) == sal_False ) &&
|
|
|
|
( m_lMediaDescriptor.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_PREVIEW(), sal_False ) == sal_False );
|
2010-01-22 22:46:39 +01:00
|
|
|
|
|
|
|
initializeUIDefaults(
|
2013-05-21 17:38:02 +02:00
|
|
|
m_xContext,
|
2010-01-22 22:46:39 +01:00
|
|
|
m_lMediaDescriptor,
|
|
|
|
bUIMode,
|
|
|
|
&m_pQuietInteraction
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-25 16:09:10 +02:00
|
|
|
void LoadEnv::initializeUIDefaults( const css::uno::Reference< css::uno::XComponentContext >& i_rxContext,
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor& io_lMediaDescriptor, const bool i_bUIMode,
|
2014-06-12 17:20:32 +02:00
|
|
|
rtl::Reference<QuietInteraction>* o_ppQuietInteraction )
|
2010-01-22 22:46:39 +01:00
|
|
|
{
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::task::XInteractionHandler > xInteractionHandler;
|
2014-04-06 19:36:08 +03:00
|
|
|
sal_Int16 nMacroMode;
|
|
|
|
sal_Int16 nUpdateMode;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2010-01-22 22:46:39 +01:00
|
|
|
if ( i_bUIMode )
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
nMacroMode = css::document::MacroExecMode::USE_CONFIG;
|
|
|
|
nUpdateMode = css::document::UpdateDocMode::ACCORDING_TO_CONFIG;
|
|
|
|
try
|
|
|
|
{
|
2013-02-25 16:09:10 +02:00
|
|
|
xInteractionHandler.set( css::task::InteractionHandler::createWithParent( i_rxContext, 0 ), css::uno::UNO_QUERY_THROW );
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&) {throw;}
|
|
|
|
catch(const css::uno::Exception& ) { }
|
|
|
|
}
|
|
|
|
// hidden mode
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nMacroMode = css::document::MacroExecMode::NEVER_EXECUTE;
|
|
|
|
nUpdateMode = css::document::UpdateDocMode::NO_UPDATE;
|
2014-06-12 17:20:32 +02:00
|
|
|
rtl::Reference<QuietInteraction> pQuietInteraction = new QuietInteraction();
|
|
|
|
xInteractionHandler = pQuietInteraction.get();
|
2010-01-22 22:46:39 +01:00
|
|
|
if ( o_ppQuietInteraction != NULL )
|
|
|
|
{
|
|
|
|
*o_ppQuietInteraction = pQuietInteraction;
|
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2010-01-22 22:46:39 +01:00
|
|
|
(xInteractionHandler.is() ) &&
|
2013-11-13 08:52:41 +01:00
|
|
|
(io_lMediaDescriptor.find(utl::MediaDescriptor::PROP_INTERACTIONHANDLER()) == io_lMediaDescriptor.end())
|
2004-01-28 13:37:23 +00:00
|
|
|
)
|
|
|
|
{
|
2013-11-13 08:52:41 +01:00
|
|
|
io_lMediaDescriptor[utl::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteractionHandler;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
if (io_lMediaDescriptor.find(utl::MediaDescriptor::PROP_MACROEXECUTIONMODE()) == io_lMediaDescriptor.end())
|
|
|
|
io_lMediaDescriptor[utl::MediaDescriptor::PROP_MACROEXECUTIONMODE()] <<= nMacroMode;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
if (io_lMediaDescriptor.find(utl::MediaDescriptor::PROP_UPDATEDOCMODE()) == io_lMediaDescriptor.end())
|
|
|
|
io_lMediaDescriptor[utl::MediaDescriptor::PROP_UPDATEDOCMODE()] <<= nUpdateMode;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadEnv::startLoading()
|
|
|
|
{
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// Handle still running processes!
|
|
|
|
if (m_xAsynchronousJob.is())
|
|
|
|
throw LoadEnvException(LoadEnvException::ID_STILL_RUNNING);
|
|
|
|
|
|
|
|
// content can not be loaded or handled
|
|
|
|
// check "classifyContent()" failed before ...
|
|
|
|
if (m_eContentType == E_UNSUPPORTED_CONTENT)
|
2013-08-20 17:58:20 +02:00
|
|
|
throw LoadEnvException(LoadEnvException::ID_UNSUPPORTED_CONTENT, "from LoadEnv::startLoading");
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// <- SAFE
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// detect its type/filter etc.
|
2004-01-28 13:37:23 +00:00
|
|
|
// These information will be available by the
|
|
|
|
// used descriptor member afterwards and is needed
|
|
|
|
// for all following operations!
|
|
|
|
// Note: An exception will be thrown, in case operation was not successfully ...
|
2004-02-26 09:39:12 +00:00
|
|
|
if (m_eContentType != E_CAN_BE_SET)/* Attention: special feature to set existing component on a frame must ignore type detection! */
|
|
|
|
impl_detectTypeAndFilter();
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// start loading the content ...
|
2013-09-26 10:02:26 +02:00
|
|
|
// Attention: Don't check m_eContentType deeper then UNSUPPORTED/SUPPORTED!
|
|
|
|
// Because it was made in the easiest way ... may a flat detection was made only.
|
2004-01-28 13:37:23 +00:00
|
|
|
// And such simple detection can fail some times .-)
|
|
|
|
// Use another strategy here. Try it and let it run into the case "loading not possible".
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bStarted = false;
|
2004-02-26 09:39:12 +00:00
|
|
|
if (
|
|
|
|
((m_eFeature & E_ALLOW_CONTENTHANDLER) == E_ALLOW_CONTENTHANDLER) &&
|
|
|
|
(m_eContentType != E_CAN_BE_SET ) /* Attention: special feature to set existing component on a frame must ignore type detection! */
|
|
|
|
)
|
|
|
|
{
|
2004-01-28 13:37:23 +00:00
|
|
|
bStarted = impl_handleContent();
|
2004-02-26 09:39:12 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
if (!bStarted)
|
|
|
|
bStarted = impl_loadContent();
|
|
|
|
|
|
|
|
// not started => general error
|
2011-11-13 23:44:40 +01:00
|
|
|
// We can't say - what was the reason for.
|
2004-01-28 13:37:23 +00:00
|
|
|
if (!bStarted)
|
2013-11-01 09:00:17 +01:00
|
|
|
throw LoadEnvException(
|
|
|
|
LoadEnvException::ID_GENERAL_ERROR, "not started");
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------
|
|
|
|
TODO
|
|
|
|
First draft does not implement timeout using [ms].
|
|
|
|
Current implementation counts yield calls only ...
|
|
|
|
-----------------------------------------------*/
|
2014-04-04 15:53:21 +02:00
|
|
|
bool LoadEnv::waitWhileLoading(sal_uInt32 nTimeout)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// Because its not a good idea to block the main thread
|
2011-11-13 23:44:40 +01:00
|
|
|
// (and we can't be sure that we are currently not used inside the
|
|
|
|
// main thread!), we can't use conditions here really. We must yield
|
2013-09-26 10:02:26 +02:00
|
|
|
// in an intelligent manner :-)
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
sal_Int32 nTime = nTimeout;
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
// SAFE -> ------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock1(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
if (!m_xAsynchronousJob.is())
|
|
|
|
break;
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock1.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE ------------------------------
|
|
|
|
|
|
|
|
Application::Yield();
|
|
|
|
|
|
|
|
// forever!
|
|
|
|
if (nTimeout==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// timed out?
|
|
|
|
--nTime;
|
|
|
|
if (nTime<1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
return !m_xAsynchronousJob.is();
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::lang::XComponent > LoadEnv::getTargetComponent() const
|
|
|
|
{
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
if (!m_xTargetFrame.is())
|
|
|
|
return css::uno::Reference< css::lang::XComponent >();
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XController > xController = m_xTargetFrame->getController();
|
|
|
|
if (!xController.is())
|
|
|
|
return css::uno::Reference< css::lang::XComponent >(m_xTargetFrame->getComponentWindow(), css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
|
|
|
|
if (!xModel.is())
|
|
|
|
return css::uno::Reference< css::lang::XComponent >(xController, css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
return css::uno::Reference< css::lang::XComponent >(xModel, css::uno::UNO_QUERY);
|
|
|
|
}
|
|
|
|
|
2006-06-19 10:24:33 +00:00
|
|
|
void SAL_CALL LoadEnvListener::loadFinished(const css::uno::Reference< css::frame::XFrameLoader >&)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-03-20 10:39:33 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2011-08-08 11:45:24 +01:00
|
|
|
if (m_bWaitingResult)
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(true);
|
2011-08-08 11:45:24 +01:00
|
|
|
m_bWaitingResult = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 10:24:33 +00:00
|
|
|
void SAL_CALL LoadEnvListener::loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >&)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-03-20 10:39:33 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2011-08-08 11:45:24 +01:00
|
|
|
if (m_bWaitingResult)
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(false);
|
2011-08-08 11:45:24 +01:00
|
|
|
m_bWaitingResult = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL LoadEnvListener::dispatchFinished(const css::frame::DispatchResultEvent& aEvent)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-03-20 10:39:33 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2011-08-08 11:45:24 +01:00
|
|
|
if (!m_bWaitingResult)
|
2004-01-28 13:37:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch(aEvent.State)
|
|
|
|
{
|
|
|
|
case css::frame::DispatchResultState::FAILURE :
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(false);
|
2004-01-28 13:37:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case css::frame::DispatchResultState::SUCCESS :
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(false);
|
2004-01-28 13:37:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case css::frame::DispatchResultState::DONTKNOW :
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(false);
|
2004-01-28 13:37:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-08-08 11:45:24 +01:00
|
|
|
m_bWaitingResult = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 10:24:33 +00:00
|
|
|
void SAL_CALL LoadEnvListener::disposing(const css::lang::EventObject&)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-03-20 10:39:33 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2011-08-08 11:45:24 +01:00
|
|
|
if (m_bWaitingResult)
|
2014-04-04 15:53:21 +02:00
|
|
|
m_pLoadEnv->impl_setResult(false);
|
2011-08-08 11:45:24 +01:00
|
|
|
m_bWaitingResult = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
void LoadEnv::impl_setResult(bool bResult)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
m_bLoaded = bResult;
|
|
|
|
|
|
|
|
impl_reactForLoadingState();
|
|
|
|
|
|
|
|
// clearing of this reference will unblock waitWhileLoading()!
|
2011-11-13 23:44:40 +01:00
|
|
|
// So we must be sure, that loading process was really finished.
|
2004-01-28 13:37:23 +00:00
|
|
|
// => do it as last operation of this method ...
|
|
|
|
m_xAsynchronousJob.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------
|
|
|
|
TODO: Is it a good idea to change Sequence<>
|
|
|
|
parameter to stl-adapter?
|
|
|
|
-----------------------------------------------*/
|
2013-04-07 12:06:47 +02:00
|
|
|
LoadEnv::EContentType LoadEnv::classifyContent(const OUString& sURL ,
|
2004-01-28 13:37:23 +00:00
|
|
|
const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
|
|
|
|
{
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// (i) Filter some special well known URL protocols,
|
|
|
|
// which can not be handled or loaded in general.
|
|
|
|
// Of course an empty URL must be ignored here too.
|
|
|
|
// Note: These URL schemata are fix and well known ...
|
|
|
|
// But there can be some additional ones, which was not
|
|
|
|
// defined at implementation time of this class :-(
|
2011-11-13 23:44:40 +01:00
|
|
|
// So we have to make sure, that the following code
|
2004-01-28 13:37:23 +00:00
|
|
|
// can detect such protocol schemata too :-)
|
|
|
|
|
|
|
|
if(
|
2011-12-26 14:20:50 -02:00
|
|
|
(sURL.isEmpty() ) ||
|
2004-01-28 13:37:23 +00:00
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_UNO )) ||
|
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SLOT )) ||
|
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MACRO )) ||
|
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_SERVICE)) ||
|
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_MAILTO )) ||
|
|
|
|
(ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_NEWS ))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return E_UNSUPPORTED_CONTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (ii) Some special URLs indicates a given input stream,
|
|
|
|
// a full featured document model directly or
|
|
|
|
// specify a request for opening an empty document.
|
|
|
|
// Such contents are loadable in general.
|
|
|
|
// But we have to check, if the media descriptor contains
|
|
|
|
// all needed resources. If they are missing - the following
|
|
|
|
// load request will fail.
|
|
|
|
|
2011-11-13 23:44:40 +01:00
|
|
|
/* Attention: The following code can't work on such special URLs!
|
2004-01-28 13:37:23 +00:00
|
|
|
It should not break the office .. but it make no sense
|
|
|
|
to start expensive object creations and complex search
|
|
|
|
algorithm if its clear, that such URLs must be handled
|
|
|
|
in a special way .-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
// creation of new documents
|
|
|
|
if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_FACTORY))
|
|
|
|
return E_CAN_BE_LOADED;
|
|
|
|
|
|
|
|
// using of an existing input stream
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor stlMediaDescriptor(lMediaDescriptor);
|
|
|
|
utl::MediaDescriptor::const_iterator pIt;
|
2004-01-28 13:37:23 +00:00
|
|
|
if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_STREAM))
|
|
|
|
{
|
2013-11-13 08:52:41 +01:00
|
|
|
pIt = stlMediaDescriptor.find(utl::MediaDescriptor::PROP_INPUTSTREAM());
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::io::XInputStream > xStream;
|
2004-07-23 10:08:28 +00:00
|
|
|
if (pIt != stlMediaDescriptor.end())
|
2004-01-28 13:37:23 +00:00
|
|
|
pIt->second >>= xStream;
|
|
|
|
if (xStream.is())
|
|
|
|
return E_CAN_BE_LOADED;
|
2013-09-08 21:49:45 +03:00
|
|
|
SAL_INFO("fwk", "LoadEnv::classifyContent(): loading from stream with right URL but invalid stream detected");
|
2004-01-28 13:37:23 +00:00
|
|
|
return E_UNSUPPORTED_CONTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// using of a full featured document
|
|
|
|
if (ProtocolCheck::isProtocol(sURL,ProtocolCheck::E_PRIVATE_OBJECT))
|
|
|
|
{
|
2013-11-13 08:52:41 +01:00
|
|
|
pIt = stlMediaDescriptor.find(utl::MediaDescriptor::PROP_MODEL());
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XModel > xModel;
|
2004-02-26 09:39:12 +00:00
|
|
|
if (pIt != stlMediaDescriptor.end())
|
2004-01-28 13:37:23 +00:00
|
|
|
pIt->second >>= xModel;
|
|
|
|
if (xModel.is())
|
2004-02-26 09:39:12 +00:00
|
|
|
return E_CAN_BE_SET;
|
2013-09-08 21:49:45 +03:00
|
|
|
SAL_INFO("fwk", "LoadEnv::classifyContent(): loading with object with right URL but invalid object detected");
|
2004-01-28 13:37:23 +00:00
|
|
|
return E_UNSUPPORTED_CONTENT;
|
|
|
|
}
|
|
|
|
|
2013-01-31 11:12:57 +02:00
|
|
|
// following operations can work on an internal type name only :-(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
|
|
|
|
css::uno::Reference< css::document::XTypeDetection > xDetect(
|
2013-08-20 17:58:20 +02:00
|
|
|
xContext->getServiceManager()->createInstanceWithContext(
|
|
|
|
"com.sun.star.document.TypeDetection", xContext),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sType = xDetect->queryTypeByURL(sURL);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2014-04-06 19:36:08 +03:00
|
|
|
css::uno::Sequence< css::beans::NamedValue > lQuery(1);
|
2013-05-30 15:02:11 +02:00
|
|
|
css::uno::Reference< css::frame::XLoaderFactory > xLoaderFactory;
|
2014-04-06 19:36:08 +03:00
|
|
|
css::uno::Reference< css::container::XEnumeration > xSet;
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Sequence< OUString > lTypesReg(1);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// (iii) If a FrameLoader service (or at least
|
|
|
|
// a Filter) can be found, which supports
|
|
|
|
// this URL - it must be a loadable content.
|
|
|
|
// Because both items are registered for types
|
|
|
|
// its enough to check for frame loaders only.
|
|
|
|
// Mos of our filters are handled by our global
|
|
|
|
// default loader. But there exist some specialized
|
|
|
|
// loader, which does not work on top of filters!
|
|
|
|
// So its not enough to search on the filter configuration.
|
|
|
|
// Further its not enough to search for types!
|
|
|
|
// Because there exist some types, which are referenced by
|
|
|
|
// other objects ... but not by filters nor frame loaders!
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPROP_TYPES(PROP_TYPES);
|
2012-03-31 15:54:07 +01:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
lTypesReg[0] = sType;
|
2012-03-31 15:54:07 +01:00
|
|
|
lQuery[0].Name = sPROP_TYPES;
|
2004-01-28 13:37:23 +00:00
|
|
|
lQuery[0].Value <<= lTypesReg;
|
|
|
|
|
2013-05-30 15:02:11 +02:00
|
|
|
xLoaderFactory = css::frame::FrameLoaderFactory::create(xContext);
|
|
|
|
xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery);
|
2004-01-28 13:37:23 +00:00
|
|
|
// at least one registered frame loader is enough!
|
|
|
|
if (xSet->hasMoreElements())
|
|
|
|
return E_CAN_BE_LOADED;
|
|
|
|
|
|
|
|
// (iv) Some URL protocols are supported by special services.
|
|
|
|
// E.g. ContentHandler.
|
|
|
|
// Such contents can be handled ... but not loaded.
|
|
|
|
|
|
|
|
lTypesReg[0] = sType;
|
2012-03-31 15:54:07 +01:00
|
|
|
lQuery[0].Name = sPROP_TYPES;
|
2004-01-28 13:37:23 +00:00
|
|
|
lQuery[0].Value <<= lTypesReg;
|
|
|
|
|
2013-05-30 15:02:11 +02:00
|
|
|
xLoaderFactory = css::frame::ContentHandlerFactory::create(xContext);
|
|
|
|
xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery);
|
2004-01-28 13:37:23 +00:00
|
|
|
// at least one registered content handler is enough!
|
|
|
|
if (xSet->hasMoreElements())
|
|
|
|
return E_CAN_BE_HANDLED;
|
|
|
|
|
|
|
|
// (v) Last but not least the UCB is used inside office to
|
|
|
|
// load contents. He has a special configuration to know
|
|
|
|
// which URL schemata can be used inside office.
|
2013-01-31 11:12:57 +02:00
|
|
|
css::uno::Reference< css::ucb::XUniversalContentBroker > xUCB(css::ucb::UniversalContentBroker::create(xContext));
|
2004-01-28 13:37:23 +00:00
|
|
|
if (xUCB->queryContentProvider(sURL).is())
|
|
|
|
return E_CAN_BE_LOADED;
|
|
|
|
|
|
|
|
// (TODO) At this point, we have no idea .-)
|
|
|
|
// But it seems to be better, to break all
|
2013-09-26 10:02:26 +02:00
|
|
|
// further requests for this URL. Otherwise
|
2004-01-28 13:37:23 +00:00
|
|
|
// we can run into some trouble.
|
|
|
|
return E_UNSUPPORTED_CONTENT;
|
|
|
|
}
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
namespace {
|
|
|
|
|
2013-09-18 21:35:50 -04:00
|
|
|
#if ENABLE_ORCUS
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescriptor, OUString& rType, OUString& rFilter)
|
|
|
|
{
|
2012-12-04 07:50:20 +01:00
|
|
|
// depending on the experimental mode
|
|
|
|
uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
|
|
|
|
if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
OUString aURL;
|
|
|
|
sal_Int32 nSize = rDescriptor.getLength();
|
|
|
|
for (sal_Int32 i = 0; i < nSize; ++i)
|
|
|
|
{
|
|
|
|
const beans::PropertyValue& rProp = rDescriptor[i];
|
|
|
|
if (rProp.Name == "URL")
|
|
|
|
{
|
|
|
|
rProp.Value >>= aURL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aURL.isEmpty() || aURL.copy(0,8).equalsIgnoreAsciiCase("private:"))
|
|
|
|
return false;
|
|
|
|
|
2013-04-09 17:08:36 -04:00
|
|
|
OUString aUseOrcus;
|
|
|
|
rtl::Bootstrap::get("LIBO_USE_ORCUS", aUseOrcus);
|
|
|
|
bool bUseOrcus = (aUseOrcus == "YES");
|
|
|
|
|
2013-04-09 00:55:02 -04:00
|
|
|
// TODO : Type must be set to be generic_Text (or any other type that
|
|
|
|
// exists) in order to find a usable loader. Exploit it as a temporary
|
|
|
|
// hack.
|
|
|
|
|
|
|
|
if (aURL.endsWith(".gnumeric"))
|
|
|
|
{
|
|
|
|
rType = "generic_Text";
|
|
|
|
rFilter = "gnumeric";
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-09 17:08:36 -04:00
|
|
|
|
|
|
|
if (!bUseOrcus)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (aURL.endsWith(".xlsx"))
|
2012-12-04 07:50:20 +01:00
|
|
|
{
|
|
|
|
rType = "generic_Text";
|
2013-04-09 00:55:02 -04:00
|
|
|
rFilter = "xlsx";
|
2012-12-04 07:50:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-04-09 00:55:02 -04:00
|
|
|
else if (aURL.endsWith(".ods"))
|
2012-07-27 22:14:39 -04:00
|
|
|
{
|
|
|
|
rType = "generic_Text";
|
2013-04-09 00:55:02 -04:00
|
|
|
rFilter = "ods";
|
2012-07-27 22:14:39 -04:00
|
|
|
return true;
|
|
|
|
}
|
2013-04-09 15:36:03 -04:00
|
|
|
else if (aURL.endsWith(".csv"))
|
|
|
|
{
|
|
|
|
rType = "generic_Text";
|
|
|
|
rFilter = "csv";
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-27 22:14:39 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-18 21:35:50 -04:00
|
|
|
#else
|
|
|
|
|
|
|
|
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>&, OUString&, OUString&)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-07-27 22:14:39 -04:00
|
|
|
}
|
2011-03-29 22:09:35 +02:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
void LoadEnv::impl_detectTypeAndFilter()
|
2014-11-19 18:30:46 +01:00
|
|
|
throw(LoadEnvException, css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2014-11-03 14:03:54 +02:00
|
|
|
static const char TYPEPROP_PREFERREDFILTER[] = "PreferredFilter";
|
|
|
|
static const char FILTERPROP_FLAGS [] = "Flags";
|
2005-03-21 12:27:42 +00:00
|
|
|
static sal_Int32 FILTERFLAG_TEMPLATEPATH = 16;
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2005-02-02 12:54:18 +00:00
|
|
|
|
2005-03-21 12:27:42 +00:00
|
|
|
// Attention: Because our stl media descriptor is a copy of an uno sequence
|
2013-09-26 10:02:26 +02:00
|
|
|
// we can't use as an in/out parameter here. Copy it before and don't forget to
|
2010-01-06 14:14:21 +01:00
|
|
|
// update structure afterwards again!
|
2005-03-21 12:27:42 +00:00
|
|
|
css::uno::Sequence< css::beans::PropertyValue > lDescriptor = m_lMediaDescriptor.getAsConstPropertyValueList();
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
|
2005-02-02 12:54:18 +00:00
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2005-02-02 12:54:18 +00:00
|
|
|
// <- SAFE
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sType, sFilter;
|
2012-07-27 22:14:39 -04:00
|
|
|
|
|
|
|
if (queryOrcusTypeAndFilter(lDescriptor, sType, sFilter) && !sType.isEmpty() && !sFilter.isEmpty())
|
|
|
|
{
|
|
|
|
// Orcus type detected. Skip the normal type detection process.
|
|
|
|
m_lMediaDescriptor << lDescriptor;
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_TYPENAME()] <<= sType;
|
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter;
|
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_FILTERPROVIDER()] <<= OUString("orcus");
|
2012-07-27 22:14:39 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-20 17:58:20 +02:00
|
|
|
css::uno::Reference< css::document::XTypeDetection > xDetect(
|
|
|
|
xContext->getServiceManager()->createInstanceWithContext(
|
|
|
|
"com.sun.star.document.TypeDetection", xContext),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
sType = xDetect->queryTypeByDescriptor(lDescriptor, sal_True); /*TODO should deep detection be able for enable/disable it from outside? */
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2005-02-02 12:54:18 +00:00
|
|
|
// no valid content -> loading not possible
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sType.isEmpty())
|
2013-08-20 17:58:20 +02:00
|
|
|
throw LoadEnvException(
|
|
|
|
LoadEnvException::ID_UNSUPPORTED_CONTENT, "type detection failed");
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2005-02-02 12:54:18 +00:00
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ResettableMutexGuard aWriteLock(m_mutex);
|
2005-03-21 12:27:42 +00:00
|
|
|
|
|
|
|
// detection was successfully => update the descriptor member of this class
|
2005-02-02 12:54:18 +00:00
|
|
|
m_lMediaDescriptor << lDescriptor;
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_TYPENAME()] <<= sType;
|
2005-03-21 12:27:42 +00:00
|
|
|
// Is there an already detected (may be preselected) filter?
|
|
|
|
// see below ...
|
2013-11-13 08:52:41 +01:00
|
|
|
sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_FILTERNAME(), OUString());
|
2005-03-21 12:27:42 +00:00
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE
|
2005-03-21 12:27:42 +00:00
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// But the type isn't enough. For loading sometimes we need more information.
|
|
|
|
// E.g. for our "_default" feature, where we recycle any frame which contains
|
2005-03-21 12:27:42 +00:00
|
|
|
// and "Untitled" document, we must know if the new document is based on a template!
|
|
|
|
// But this information is available as a filter property only.
|
|
|
|
// => We must try(!) to detect the right filter for this load request.
|
|
|
|
// On the other side ... if no filter is available .. ignore it.
|
|
|
|
// Then the type information must be enough.
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sFilter.isEmpty())
|
2005-03-21 12:27:42 +00:00
|
|
|
{
|
|
|
|
// no -> try to find a preferred filter for the detected type.
|
2013-09-26 10:02:26 +02:00
|
|
|
// Don't forget to update the media descriptor.
|
2005-03-21 12:27:42 +00:00
|
|
|
css::uno::Reference< css::container::XNameAccess > xTypeCont(xDetect, css::uno::UNO_QUERY_THROW);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
::comphelper::SequenceAsHashMap lTypeProps(xTypeCont->getByName(sType));
|
2013-04-07 12:06:47 +02:00
|
|
|
sFilter = lTypeProps.getUnpackedValueOrDefault(TYPEPROP_PREFERREDFILTER, OUString());
|
2011-12-26 14:20:50 -02:00
|
|
|
if (!sFilter.isEmpty())
|
2005-03-21 12:27:42 +00:00
|
|
|
{
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.reset();
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_FILTERNAME()] <<= sFilter;
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2005-03-21 12:27:42 +00:00
|
|
|
// <- SAFE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const css::container::NoSuchElementException&)
|
|
|
|
{}
|
|
|
|
}
|
2005-04-18 11:11:34 +00:00
|
|
|
|
2005-03-21 12:27:42 +00:00
|
|
|
// check if the filter (if one exists) points to a template format filter.
|
2005-04-18 11:11:34 +00:00
|
|
|
// Then we have to add the property "AsTemplate".
|
|
|
|
// We need this information to decide afterwards if we can use a "recycle frame"
|
2013-09-26 10:02:26 +02:00
|
|
|
// for target "_default" or has to create a new one every time.
|
|
|
|
// On the other side we have to suppress that, if this property already exists
|
|
|
|
// and should trigger a special handling. Then the outside call of this method here,
|
2005-04-18 11:11:34 +00:00
|
|
|
// has to know, what he is doing .-)
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bIsOwnTemplate = false;
|
2011-12-26 14:20:50 -02:00
|
|
|
if (!sFilter.isEmpty())
|
2005-03-21 12:27:42 +00:00
|
|
|
{
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::container::XNameAccess > xFilterCont(xContext->getServiceManager()->createInstanceWithContext(SERVICENAME_FILTERFACTORY, xContext), css::uno::UNO_QUERY_THROW);
|
2005-03-21 12:27:42 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
::comphelper::SequenceAsHashMap lFilterProps(xFilterCont->getByName(sFilter));
|
|
|
|
sal_Int32 nFlags = lFilterProps.getUnpackedValueOrDefault(FILTERPROP_FLAGS, (sal_Int32)0);
|
|
|
|
bIsOwnTemplate = ((nFlags & FILTERFLAG_TEMPLATEPATH) == FILTERFLAG_TEMPLATEPATH);
|
|
|
|
}
|
|
|
|
catch(const css::container::NoSuchElementException&)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
if (bIsOwnTemplate)
|
|
|
|
{
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.reset();
|
2013-09-26 10:02:26 +02:00
|
|
|
// Don't overwrite external decisions! See comments before ...
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::const_iterator pAsTemplateItem = m_lMediaDescriptor.find(utl::MediaDescriptor::PROP_ASTEMPLATE());
|
2005-04-12 14:58:32 +00:00
|
|
|
if (pAsTemplateItem == m_lMediaDescriptor.end())
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_ASTEMPLATE()] <<= sal_True;
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2005-03-21 12:27:42 +00:00
|
|
|
// <- SAFE
|
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool LoadEnv::impl_handleContent()
|
2014-11-19 18:28:46 +01:00
|
|
|
throw(LoadEnvException, css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// SAFE -> -----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-02-13 18:25:22 +04:00
|
|
|
// the type must exist inside the descriptor ... otherwise this class is implemented wrong :-)
|
2013-11-13 08:52:41 +01:00
|
|
|
OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_TYPENAME(), OUString());
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sType.isEmpty())
|
2004-01-28 13:37:23 +00:00
|
|
|
throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR);
|
|
|
|
|
|
|
|
// convert media descriptor and URL to right format for later interface call!
|
|
|
|
css::uno::Sequence< css::beans::PropertyValue > lDescriptor;
|
|
|
|
m_lMediaDescriptor >> lDescriptor;
|
|
|
|
css::util::URL aURL = m_aURL;
|
|
|
|
|
2013-03-03 17:11:39 +01:00
|
|
|
// get necessary container to query for a handler object
|
2013-05-30 15:02:11 +02:00
|
|
|
css::uno::Reference< css::frame::XLoaderFactory > xLoaderFactory = css::frame::ContentHandlerFactory::create(m_xContext);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE -----------------------------------
|
|
|
|
|
|
|
|
// query
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Sequence< OUString > lTypeReg(1);
|
2004-01-28 13:37:23 +00:00
|
|
|
lTypeReg[0] = sType;
|
|
|
|
|
|
|
|
css::uno::Sequence< css::beans::NamedValue > lQuery(1);
|
2014-12-18 13:19:13 +01:00
|
|
|
lQuery[0].Name = PROP_TYPES;
|
2004-01-28 13:37:23 +00:00
|
|
|
lQuery[0].Value <<= lTypeReg;
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPROP_NAME(PROP_NAME);
|
2012-03-31 15:54:07 +01:00
|
|
|
|
2013-05-30 15:02:11 +02:00
|
|
|
css::uno::Reference< css::container::XEnumeration > xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery);
|
2004-01-28 13:37:23 +00:00
|
|
|
while(xSet->hasMoreElements())
|
|
|
|
{
|
|
|
|
::comphelper::SequenceAsHashMap lProps (xSet->nextElement());
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sHandler = lProps.getUnpackedValueOrDefault(sPROP_NAME, OUString());
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XNotifyingDispatch > xHandler;
|
|
|
|
try
|
|
|
|
{
|
2013-05-30 15:02:11 +02:00
|
|
|
xHandler = css::uno::Reference< css::frame::XNotifyingDispatch >(xLoaderFactory->createInstance(sHandler), css::uno::UNO_QUERY);
|
2004-01-28 13:37:23 +00:00
|
|
|
if (!xHandler.is())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ continue; }
|
|
|
|
|
|
|
|
// SAFE -> -----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aWriteLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
m_xAsynchronousJob = xHandler;
|
2011-08-08 11:45:24 +01:00
|
|
|
LoadEnvListener* pListener = new LoadEnvListener(this);
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE -----------------------------------
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XDispatchResultListener > xListener(static_cast< css::frame::XDispatchResultListener* >(pListener), css::uno::UNO_QUERY);
|
|
|
|
xHandler->dispatchWithNotification(aURL, lDescriptor, xListener);
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
return true;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
return false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool LoadEnv::impl_furtherDocsAllowed()
|
2005-11-11 11:06:12 +00:00
|
|
|
{
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ResettableMutexGuard aReadLock(m_mutex);
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2005-11-11 11:06:12 +00:00
|
|
|
// <- SAFE
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bAllowed = true;
|
2005-11-11 11:06:12 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
|
2013-05-21 17:38:02 +02:00
|
|
|
xContext,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString("org.openoffice.Office.Common/"),
|
|
|
|
OUString("Misc"),
|
|
|
|
OUString("MaxOpenDocuments"),
|
2005-11-11 11:06:12 +00:00
|
|
|
::comphelper::ConfigurationHelper::E_READONLY);
|
|
|
|
|
|
|
|
// NIL means: count of allowed documents = infinite !
|
2010-11-05 10:31:15 +08:00
|
|
|
// => return sal_True
|
2005-11-11 11:06:12 +00:00
|
|
|
if ( ! aVal.hasValue())
|
2014-04-04 15:53:21 +02:00
|
|
|
bAllowed = true;
|
2005-11-11 11:06:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nMaxOpenDocuments = 0;
|
|
|
|
aVal >>= nMaxOpenDocuments;
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
|
2013-05-21 17:38:02 +02:00
|
|
|
css::frame::Desktop::create(xContext),
|
2005-11-11 11:06:12 +00:00
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
FrameListAnalyzer aAnalyzer(xDesktop,
|
|
|
|
css::uno::Reference< css::frame::XFrame >(),
|
|
|
|
FrameListAnalyzer::E_HELP |
|
|
|
|
FrameListAnalyzer::E_BACKINGCOMPONENT |
|
|
|
|
FrameListAnalyzer::E_HIDDEN);
|
|
|
|
|
|
|
|
sal_Int32 nOpenDocuments = aAnalyzer.m_lOtherVisibleFrames.getLength();
|
|
|
|
bAllowed = (nOpenDocuments < nMaxOpenDocuments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const css::uno::Exception&)
|
2014-04-04 15:53:21 +02:00
|
|
|
{ bAllowed = true; } // !! internal errors are no reason to disturb the office from opening documents .-)
|
2005-11-11 11:06:12 +00:00
|
|
|
|
|
|
|
if ( ! bAllowed )
|
|
|
|
{
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.reset();
|
2005-11-11 11:06:12 +00:00
|
|
|
css::uno::Reference< css::task::XInteractionHandler > xInteraction = m_lMediaDescriptor.getUnpackedValueOrDefault(
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::PROP_INTERACTIONHANDLER(),
|
2005-11-11 11:06:12 +00:00
|
|
|
css::uno::Reference< css::task::XInteractionHandler >());
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2005-11-11 11:06:12 +00:00
|
|
|
// <- SAFE
|
|
|
|
|
|
|
|
if (xInteraction.is())
|
|
|
|
{
|
|
|
|
css::uno::Any aInteraction;
|
|
|
|
css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations(2);
|
|
|
|
|
2010-04-24 00:09:05 +02:00
|
|
|
comphelper::OInteractionAbort* pAbort = new comphelper::OInteractionAbort();
|
|
|
|
comphelper::OInteractionApprove* pApprove = new comphelper::OInteractionApprove();
|
2005-11-11 11:06:12 +00:00
|
|
|
|
|
|
|
lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >(
|
|
|
|
static_cast< css::task::XInteractionContinuation* >(pAbort),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >(
|
|
|
|
static_cast< css::task::XInteractionContinuation* >(pApprove),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
css::task::ErrorCodeRequest aErrorCode;
|
|
|
|
aErrorCode.ErrCode = ERRCODE_SFX_NOMOREDOCUMENTSALLOWED;
|
|
|
|
aInteraction <<= aErrorCode;
|
2010-04-24 00:09:05 +02:00
|
|
|
xInteraction->handle( InteractionRequest::CreateRequest(aInteraction, lContinuations) );
|
2005-11-11 11:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bAllowed;
|
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool LoadEnv::impl_loadContent()
|
2014-11-19 18:25:42 +01:00
|
|
|
throw(LoadEnvException, css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// SAFE -> -----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aWriteLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// search or create right target frame
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTarget = m_sTarget;
|
2005-11-11 11:06:12 +00:00
|
|
|
if (TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT))
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
m_xTargetFrame = impl_searchAlreadyLoaded();
|
2004-04-21 12:55:35 +00:00
|
|
|
if (m_xTargetFrame.is())
|
|
|
|
{
|
2014-04-04 15:53:21 +02:00
|
|
|
impl_setResult(true);
|
|
|
|
return true;
|
2004-04-21 12:55:35 +00:00
|
|
|
}
|
|
|
|
m_xTargetFrame = impl_searchRecycleTarget();
|
2005-11-11 11:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! m_xTargetFrame.is())
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
(TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_BLANK )) ||
|
|
|
|
(TargetHelper::matchSpecialTarget(sTarget, TargetHelper::E_DEFAULT))
|
|
|
|
)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2005-11-11 11:06:12 +00:00
|
|
|
if (! impl_furtherDocsAllowed())
|
2014-04-04 15:53:21 +02:00
|
|
|
return false;
|
2005-11-11 11:06:12 +00:00
|
|
|
m_xTargetFrame = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0);
|
2004-01-28 13:37:23 +00:00
|
|
|
m_bCloseFrameOnError = m_xTargetFrame.is();
|
|
|
|
}
|
2005-11-11 11:06:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nFlags = m_nSearchFlags & ~css::frame::FrameSearchFlag::CREATE;
|
|
|
|
m_xTargetFrame = m_xBaseFrame->findFrame(sTarget, nFlags);
|
|
|
|
if (! m_xTargetFrame.is())
|
|
|
|
{
|
|
|
|
if (! impl_furtherDocsAllowed())
|
2014-04-04 15:53:21 +02:00
|
|
|
return false;
|
2005-11-11 11:06:12 +00:00
|
|
|
m_xTargetFrame = m_xBaseFrame->findFrame(SPECIALTARGET_BLANK, 0);
|
|
|
|
m_bCloseFrameOnError = m_xTargetFrame.is();
|
|
|
|
}
|
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 15:13:49 +00:00
|
|
|
// If we couldn't find a valid frame or the frame has no container window
|
|
|
|
// we have to throw an exception.
|
2006-02-07 09:24:07 +00:00
|
|
|
if (
|
|
|
|
( ! m_xTargetFrame.is() ) ||
|
|
|
|
( ! m_xTargetFrame->getContainerWindow().is() )
|
|
|
|
)
|
2004-01-28 13:37:23 +00:00
|
|
|
throw LoadEnvException(LoadEnvException::ID_NO_TARGET_FOUND);
|
|
|
|
|
2006-02-07 09:24:07 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > xTargetFrame = m_xTargetFrame;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2005-03-23 15:15:20 +00:00
|
|
|
// Now we have a valid frame ... and type detection was already done.
|
2013-09-26 10:02:26 +02:00
|
|
|
// We should apply the module dependent window position and size to the
|
2005-03-23 15:15:20 +00:00
|
|
|
// frame window.
|
|
|
|
impl_applyPersistentWindowState(xTargetFrame->getContainerWindow());
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// Don't forget to lock task for following load process. Otherwise it could die
|
|
|
|
// during this operation runs by terminating the office or closing this task via api.
|
|
|
|
// If we set this lock "close()" will return false and closing will be broken.
|
|
|
|
// Attention: Don't forget to reset this lock again after finishing operation.
|
|
|
|
// Otherwise task AND office couldn't die!!!
|
|
|
|
// This includes gracefully handling of Exceptions (Runtime!) too ...
|
2013-09-26 10:02:26 +02:00
|
|
|
// That's why we use a specialized guard, which will reset the lock
|
2004-01-28 13:37:23 +00:00
|
|
|
// if it will be run out of scope.
|
|
|
|
|
|
|
|
// Note further: ignore if this internal guard already contains a resource.
|
2013-09-26 10:02:26 +02:00
|
|
|
// Might impl_searchRecylcTarget() set it before. But in case this impl-method wasn't used
|
2004-01-28 13:37:23 +00:00
|
|
|
// and the target frame was new created ... this lock here must be set!
|
|
|
|
css::uno::Reference< css::document::XActionLockable > xTargetLock(xTargetFrame, css::uno::UNO_QUERY);
|
|
|
|
m_aTargetLock.setResource(xTargetLock);
|
|
|
|
|
|
|
|
// Add status indicator to descriptor. Loader can show an progresses then.
|
|
|
|
// But don't do it, if loading should be hidden or preview is used ...!
|
|
|
|
// So we prevent our code against wrong using. Why?
|
|
|
|
// It could be, that using of this progress could make trouble. e.g. He make window visible ...
|
|
|
|
// but shouldn't do that. But if no indicator is available ... nobody has a chance to do that!
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bHidden = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN() , sal_False );
|
|
|
|
bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_MINIMIZED() , sal_False );
|
|
|
|
bool bPreview = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW() , sal_False );
|
2013-11-13 08:52:41 +01:00
|
|
|
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >());
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2004-07-23 10:08:28 +00:00
|
|
|
if (!bHidden && !bMinimized && !bPreview && !xProgress.is())
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// Note: its an optional interface!
|
|
|
|
css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
|
|
|
|
if (xProgressFactory.is())
|
|
|
|
{
|
|
|
|
xProgress = xProgressFactory->createStatusIndicator();
|
|
|
|
if (xProgress.is())
|
2013-11-13 08:52:41 +01:00
|
|
|
m_lMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert media descriptor and URL to right format for later interface call!
|
|
|
|
css::uno::Sequence< css::beans::PropertyValue > lDescriptor;
|
|
|
|
m_lMediaDescriptor >> lDescriptor;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sURL = m_aURL.Complete;
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2004-02-26 09:39:12 +00:00
|
|
|
// try to locate any interested frame loader
|
|
|
|
css::uno::Reference< css::uno::XInterface > xLoader = impl_searchLoader();
|
|
|
|
css::uno::Reference< css::frame::XFrameLoader > xAsyncLoader(xLoader, css::uno::UNO_QUERY);
|
|
|
|
css::uno::Reference< css::frame::XSynchronousFrameLoader > xSyncLoader (xLoader, css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
if (xAsyncLoader.is())
|
|
|
|
{
|
|
|
|
m_xAsynchronousJob = xAsyncLoader;
|
2011-08-08 11:45:24 +01:00
|
|
|
LoadEnvListener* pListener = new LoadEnvListener(this);
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2004-02-26 09:39:12 +00:00
|
|
|
// <- SAFE -----------------------------------
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XLoadEventListener > xListener(static_cast< css::frame::XLoadEventListener* >(pListener), css::uno::UNO_QUERY);
|
|
|
|
xAsyncLoader->load(xTargetFrame, sURL, lDescriptor, xListener);
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
return true;
|
2004-02-26 09:39:12 +00:00
|
|
|
}
|
2012-10-11 17:36:33 +01:00
|
|
|
else if (xSyncLoader.is())
|
2004-02-26 09:39:12 +00:00
|
|
|
{
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bResult = xSyncLoader->load(lDescriptor, xTargetFrame);
|
2004-02-26 09:39:12 +00:00
|
|
|
// react for the result here, so the outside waiting
|
|
|
|
// code can ask for it later.
|
|
|
|
impl_setResult(bResult);
|
|
|
|
// But the return value indicates a valid started(!) operation.
|
2013-09-26 10:02:26 +02:00
|
|
|
// And that's true every time we reach this line :-)
|
2014-04-04 15:53:21 +02:00
|
|
|
return true;
|
2004-02-26 09:39:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2004-02-26 09:39:12 +00:00
|
|
|
// <- SAFE
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
return false;
|
2004-02-26 09:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::uno::XInterface > LoadEnv::impl_searchLoader()
|
|
|
|
{
|
|
|
|
// SAFE -> -----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2004-02-26 09:39:12 +00:00
|
|
|
|
|
|
|
// special mode to set an existing component on this frame
|
2013-09-26 10:02:26 +02:00
|
|
|
// In such case the loader is fix. It must be the SFX based implementation,
|
2004-02-26 09:39:12 +00:00
|
|
|
// which can create a view on top of such xModel components :-)
|
|
|
|
if (m_eContentType == E_CAN_BE_SET)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-05-29 08:09:33 +02:00
|
|
|
return css::frame::OfficeFrameLoader::create(m_xContext);
|
2004-02-26 09:39:12 +00:00
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
throw LoadEnvException(LoadEnvException::ID_INVALID_ENVIRONMENT);
|
|
|
|
}
|
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// Otherwise ...
|
2004-02-26 09:39:12 +00:00
|
|
|
// We need this type information to locate an registered frame loader
|
2011-11-13 23:44:40 +01:00
|
|
|
// Without such information we can't work!
|
2013-11-13 08:52:41 +01:00
|
|
|
OUString sType = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_TYPENAME(), OUString());
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sType.isEmpty())
|
2004-02-26 09:39:12 +00:00
|
|
|
throw LoadEnvException(LoadEnvException::ID_INVALID_MEDIADESCRIPTOR);
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// try to locate any interested frame loader
|
2013-05-30 15:02:11 +02:00
|
|
|
css::uno::Reference< css::frame::XLoaderFactory > xLoaderFactory = css::frame::FrameLoaderFactory::create(m_xContext);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE -----------------------------------
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Sequence< OUString > lTypesReg(1);
|
2004-01-28 13:37:23 +00:00
|
|
|
lTypesReg[0] = sType;
|
|
|
|
|
|
|
|
css::uno::Sequence< css::beans::NamedValue > lQuery(1);
|
2014-12-18 13:19:13 +01:00
|
|
|
lQuery[0].Name = PROP_TYPES;
|
2004-01-28 13:37:23 +00:00
|
|
|
lQuery[0].Value <<= lTypesReg;
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPROP_NAME(PROP_NAME);
|
2012-03-31 15:54:07 +01:00
|
|
|
|
2013-05-30 15:02:11 +02:00
|
|
|
css::uno::Reference< css::container::XEnumeration > xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery);
|
2004-01-28 13:37:23 +00:00
|
|
|
while(xSet->hasMoreElements())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-06-01 14:28:34 +01:00
|
|
|
// try everyone ...
|
|
|
|
// Ignore any loader, which makes trouble :-)
|
|
|
|
::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement());
|
|
|
|
OUString sLoader = lLoaderProps.getUnpackedValueOrDefault(sPROP_NAME, OUString());
|
|
|
|
css::uno::Reference< css::uno::XInterface > xLoader;
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
xLoader = xLoaderFactory->createInstance(sLoader);
|
2004-02-26 09:39:12 +00:00
|
|
|
if (xLoader.is())
|
|
|
|
return xLoader;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ continue; }
|
|
|
|
}
|
|
|
|
|
2004-02-26 09:39:12 +00:00
|
|
|
return css::uno::Reference< css::uno::XInterface >();
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 12:57:00 +00:00
|
|
|
void LoadEnv::impl_jumpToMark(const css::uno::Reference< css::frame::XFrame >& xFrame,
|
|
|
|
const css::util::URL& aURL )
|
|
|
|
{
|
2011-12-26 14:20:50 -02:00
|
|
|
if (aURL.Mark.isEmpty())
|
2006-02-09 12:57:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XDispatchProvider > xProvider(xFrame, css::uno::UNO_QUERY);
|
|
|
|
if (! xProvider.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2006-02-09 12:57:00 +00:00
|
|
|
// <- SAFE
|
|
|
|
|
|
|
|
css::util::URL aCmd;
|
2013-11-04 14:00:40 +02:00
|
|
|
aCmd.Complete = ".uno:JumpToMark";
|
2006-02-09 12:57:00 +00:00
|
|
|
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::util::XURLTransformer > xParser(css::util::URLTransformer::create(xContext));
|
2006-02-09 12:57:00 +00:00
|
|
|
xParser->parseStrict(aCmd);
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XDispatch > xDispatcher = xProvider->queryDispatch(aCmd, SPECIALTARGET_SELF, 0);
|
|
|
|
if (! xDispatcher.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
::comphelper::SequenceAsHashMap lArgs;
|
2013-04-07 12:06:47 +02:00
|
|
|
lArgs[OUString("Bookmark")] <<= aURL.Mark;
|
2006-02-09 12:57:00 +00:00
|
|
|
xDispatcher->dispatch(aCmd, lArgs.getAsConstPropertyValueList());
|
|
|
|
}
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded()
|
|
|
|
throw(LoadEnvException, css::uno::RuntimeException)
|
|
|
|
{
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::MutexGuard g(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// such search is allowed for special requests only ...
|
|
|
|
// or better its not allowed for some requests in general :-)
|
|
|
|
if (
|
2007-11-26 12:45:13 +00:00
|
|
|
( ! TargetHelper::matchSpecialTarget(m_sTarget, TargetHelper::E_DEFAULT) ) ||
|
2013-11-13 08:52:41 +01:00
|
|
|
(m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) ||
|
|
|
|
// (m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN() , sal_False) == sal_True) ||
|
|
|
|
(m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True)
|
2004-01-28 13:37:23 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
}
|
|
|
|
|
|
|
|
// check URL
|
2011-11-13 23:44:40 +01:00
|
|
|
// May its not useful to start expensive document search, if it
|
2004-01-28 13:37:23 +00:00
|
|
|
// can fail only .. because we load from a stream or model directly!
|
|
|
|
if (
|
|
|
|
(ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM )) ||
|
|
|
|
(ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT ))
|
|
|
|
/*TODO should be private:factory here tested too? */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
}
|
|
|
|
|
2013-02-13 18:25:22 +04:00
|
|
|
// otherwise - iterate through the tasks of the desktop container
|
2004-01-28 13:37:23 +00:00
|
|
|
// to find out, which of them might contains the requested document
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::frame::XDesktop2 > xSupplier = css::frame::Desktop::create( m_xContext );
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::container::XIndexAccess > xTaskList(xSupplier->getFrames() , css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
if (!xTaskList.is())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >(); // task list can be empty!
|
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// Note: To detect if a document was already loaded before
|
2011-11-13 23:44:40 +01:00
|
|
|
// we check URLs here only. But might the existing and the required
|
2004-01-28 13:37:23 +00:00
|
|
|
// document has different versions! Then its URLs are the same ...
|
2013-11-13 08:52:41 +01:00
|
|
|
sal_Int16 nNewVersion = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int16)(-1));
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2007-11-26 12:45:13 +00:00
|
|
|
// will be used to save the first hidden frame referring the searched model
|
2011-11-13 23:44:40 +01:00
|
|
|
// Normally we are interested on visible frames ... but if there is no such visible
|
2013-09-26 10:02:26 +02:00
|
|
|
// frame we refer to any hidden frame also (but as fallback only).
|
2007-11-26 12:45:13 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > xHiddenTask;
|
|
|
|
css::uno::Reference< css::frame::XFrame > xTask;
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
sal_Int32 count = xTaskList->getCount();
|
|
|
|
for (sal_Int32 i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// locate model of task
|
|
|
|
// Note: Without a model there is no chance to decide if
|
|
|
|
// this task contains the searched document or not!
|
|
|
|
xTaskList->getByIndex(i) >>= xTask;
|
|
|
|
if (!xTask.is())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XController > xController = xTask->getController();
|
|
|
|
if (!xController.is())
|
2007-11-26 12:45:13 +00:00
|
|
|
{
|
|
|
|
xTask.clear ();
|
2004-01-28 13:37:23 +00:00
|
|
|
continue;
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
|
|
|
|
if (!xModel.is())
|
2007-11-26 12:45:13 +00:00
|
|
|
{
|
|
|
|
xTask.clear ();
|
2004-01-28 13:37:23 +00:00
|
|
|
continue;
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// don't check the complete URL here.
|
|
|
|
// use its main part - ignore optional jumpmarks!
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString sURL = xModel->getURL();
|
2010-08-09 10:47:38 +02:00
|
|
|
if (!::utl::UCBContentHelper::EqualURLs( m_aURL.Main, sURL ))
|
2007-11-26 12:45:13 +00:00
|
|
|
{
|
|
|
|
xTask.clear ();
|
2004-01-28 13:37:23 +00:00
|
|
|
continue;
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// get the original load arguments from the current document
|
2011-11-13 23:44:40 +01:00
|
|
|
// and decide if its really the same then the one will be.
|
2004-01-28 13:37:23 +00:00
|
|
|
// It must be visible and must use the same file revision ...
|
|
|
|
// or must not have any file revision set (-1 == -1!)
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor lOldDocDescriptor(xModel->getArgs());
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2013-11-13 08:52:41 +01:00
|
|
|
if (lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int32)(-1)) != nNewVersion)
|
2007-11-26 12:45:13 +00:00
|
|
|
{
|
|
|
|
xTask.clear ();
|
2004-01-28 13:37:23 +00:00
|
|
|
continue;
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2007-11-26 12:45:13 +00:00
|
|
|
// Hidden frames are special.
|
|
|
|
// They will be used as "last chance" if there is no visible frame pointing to the same model.
|
|
|
|
// Safe the result but continue with current loop might be looking for other visible frames.
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bIsHidden = lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN(), sal_False);
|
2007-11-26 12:45:13 +00:00
|
|
|
if (
|
|
|
|
( bIsHidden ) &&
|
|
|
|
( ! xHiddenTask.is())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
xHiddenTask = xTask;
|
|
|
|
xTask.clear ();
|
2004-01-28 13:37:23 +00:00
|
|
|
continue;
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2007-11-26 12:45:13 +00:00
|
|
|
// We found a visible task pointing to the right model ...
|
|
|
|
// Break search.
|
|
|
|
break;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
2012-02-05 11:53:47 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-01-28 13:37:23 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ continue; }
|
|
|
|
}
|
|
|
|
|
2007-11-26 12:45:13 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > xResult;
|
|
|
|
if (xTask.is())
|
|
|
|
xResult = xTask;
|
2012-10-11 10:11:26 +01:00
|
|
|
else if (xHiddenTask.is())
|
2007-11-26 12:45:13 +00:00
|
|
|
xResult = xHiddenTask;
|
|
|
|
|
|
|
|
if (xResult.is())
|
|
|
|
{
|
2011-11-13 23:44:40 +01:00
|
|
|
// Now we are sure, that this task includes the searched document.
|
|
|
|
// It's time to activate it. As special feature we try to jump internally
|
2007-11-26 12:45:13 +00:00
|
|
|
// if an optional jumpmark is given too.
|
2011-12-26 14:20:50 -02:00
|
|
|
if (!m_aURL.Mark.isEmpty())
|
2007-11-26 12:45:13 +00:00
|
|
|
impl_jumpToMark(xResult, m_aURL);
|
|
|
|
|
|
|
|
// bring it to front and make sure it's visible...
|
2014-04-04 15:53:21 +02:00
|
|
|
impl_makeFrameWindowVisible(xResult->getContainerWindow(), true);
|
2007-11-26 12:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xResult;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) const
|
2005-03-21 12:27:42 +00:00
|
|
|
{
|
|
|
|
css::uno::Reference< css::document::XActionLockable > xLock(xFrame, css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
// ? no lock interface ?
|
|
|
|
// Might its an external written frame implementation :-(
|
|
|
|
// Allowing using of it ... but it can fail if its not synchronized with our processes !
|
|
|
|
if (!xLock.is())
|
2014-04-04 15:53:21 +02:00
|
|
|
return false;
|
2005-03-21 12:27:42 +00:00
|
|
|
|
2011-11-13 23:44:40 +01:00
|
|
|
// Otherwise we have to look for any other existing lock.
|
2005-03-21 12:27:42 +00:00
|
|
|
return xLock->isActionLocked();
|
|
|
|
}
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget()
|
2014-10-10 10:09:51 +02:00
|
|
|
throw(LoadEnvException, css::uno::RuntimeException, std::exception)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// SAFE -> ..................................
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2005-02-02 12:54:18 +00:00
|
|
|
// The special backing mode frame will be recycled by definition!
|
2013-09-26 10:02:26 +02:00
|
|
|
// It doesn't matter if somewhere wants to create a new view
|
2005-02-02 12:54:18 +00:00
|
|
|
// or open a new untitled document ...
|
|
|
|
// The only exception form that - hidden frames!
|
2013-11-13 08:52:41 +01:00
|
|
|
if (m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN(), sal_False) == sal_True)
|
2004-01-28 13:37:23 +00:00
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::frame::XFramesSupplier > xSupplier( css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY);
|
2004-01-28 13:37:23 +00:00
|
|
|
FrameListAnalyzer aTasksAnalyzer(xSupplier, css::uno::Reference< css::frame::XFrame >(), FrameListAnalyzer::E_BACKINGCOMPONENT);
|
|
|
|
if (aTasksAnalyzer.m_xBackingComponent.is())
|
2005-03-21 12:27:42 +00:00
|
|
|
{
|
|
|
|
if (!impl_isFrameAlreadyUsedForLoading(aTasksAnalyzer.m_xBackingComponent))
|
2007-07-03 13:16:25 +00:00
|
|
|
{
|
|
|
|
// bring it to front ...
|
2014-04-04 15:53:21 +02:00
|
|
|
impl_makeFrameWindowVisible(aTasksAnalyzer.m_xBackingComponent->getContainerWindow(), true);
|
2005-03-21 12:27:42 +00:00
|
|
|
return aTasksAnalyzer.m_xBackingComponent;
|
2007-07-03 13:16:25 +00:00
|
|
|
}
|
2005-03-21 12:27:42 +00:00
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2011-11-13 23:44:40 +01:00
|
|
|
// These states indicates a wish for creation of a new view in general.
|
2005-02-02 12:54:18 +00:00
|
|
|
if (
|
2013-11-13 08:52:41 +01:00
|
|
|
(m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ASTEMPLATE() , sal_False) == sal_True) ||
|
|
|
|
(m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_OPENNEWVIEW(), sal_False) == sal_True)
|
2005-02-02 12:54:18 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
}
|
|
|
|
|
2013-09-26 10:02:26 +02:00
|
|
|
// On the other side some special URLs will open a new frame every time (expecting
|
2004-03-30 06:45:16 +00:00
|
|
|
// they can use the backing-mode frame!)
|
|
|
|
if (
|
|
|
|
(ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_FACTORY )) ||
|
|
|
|
(ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_STREAM )) ||
|
|
|
|
(ProtocolCheck::isProtocol(m_aURL.Complete, ProtocolCheck::E_PRIVATE_OBJECT ))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No backing frame! No special URL => recycle active task - if possible.
|
|
|
|
// Means - if it does not already contains a modified document, or
|
|
|
|
// use another office module.
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XFrame > xTask = xSupplier->getActiveFrame();
|
|
|
|
|
|
|
|
// not a real error - but might a focus problem!
|
|
|
|
if (!xTask.is())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2013-09-26 11:44:54 +02:00
|
|
|
// not a real error - may it's a view only
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XController > xController = xTask->getController();
|
|
|
|
if (!xController.is())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2013-09-26 11:44:54 +02:00
|
|
|
// not a real error - may it's a db component instead of a full featured office document
|
2004-01-28 13:37:23 +00:00
|
|
|
css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
|
|
|
|
if (!xModel.is())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2013-02-28 18:11:24 -04:00
|
|
|
// get some more information ...
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
// A valid set URL means: there is already a location for this document.
|
|
|
|
// => it was saved there or opened from there. Such Documents can not be used here.
|
|
|
|
// We search for empty document ... created by a private:factory/ URL!
|
|
|
|
if (xModel->getURL().getLength()>0)
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
|
|
|
// The old document must be unmodified ...
|
|
|
|
css::uno::Reference< css::util::XModifiable > xModified(xModel, css::uno::UNO_QUERY);
|
|
|
|
if (xModified->isModified())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWindow = VCLUnoHelper::GetWindow(xTask->getContainerWindow());
|
2006-02-07 09:24:07 +00:00
|
|
|
if (pWindow && pWindow->IsInModalMode())
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// find out the application type of this document
|
|
|
|
// We can recycle only documents, which uses the same application
|
|
|
|
// then the new one.
|
|
|
|
SvtModuleOptions::EFactory eOldApp = SvtModuleOptions::ClassifyFactoryByModel(xModel);
|
|
|
|
SvtModuleOptions::EFactory eNewApp = SvtModuleOptions::ClassifyFactoryByURL (m_aURL.Complete, m_lMediaDescriptor.getAsConstPropertyValueList());
|
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE ..................................
|
|
|
|
|
|
|
|
if (eOldApp != eNewApp)
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2014-02-06 21:22:42 +01:00
|
|
|
// OK this task seems to be usable for recycling
|
2004-01-28 13:37:23 +00:00
|
|
|
// But we should mark it as such - means set an action lock.
|
2014-08-01 16:56:25 +09:00
|
|
|
// Otherwise it would be used more than ones or will be destroyed
|
2004-01-28 13:37:23 +00:00
|
|
|
// by a close() or terminate() request.
|
|
|
|
// But if such lock already exist ... it means this task is used for
|
|
|
|
// any other operation already. Don't use it then.
|
2005-03-21 12:27:42 +00:00
|
|
|
if (impl_isFrameAlreadyUsedForLoading(xTask))
|
2004-01-28 13:37:23 +00:00
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
|
2006-02-07 09:24:07 +00:00
|
|
|
// OK - there is a valid target frame.
|
|
|
|
// But may be it contains already a document.
|
2013-09-26 10:02:26 +02:00
|
|
|
// Then we have to ask it, if it allows recycling of this frame .-)
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bReactivateOldControllerOnError = false;
|
2006-02-07 09:24:07 +00:00
|
|
|
css::uno::Reference< css::frame::XController > xOldDoc = xTask->getController();
|
|
|
|
if (xOldDoc.is())
|
|
|
|
{
|
|
|
|
bReactivateOldControllerOnError = xOldDoc->suspend(sal_True);
|
|
|
|
if (! bReactivateOldControllerOnError)
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
|
|
|
}
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// SAFE -> ..................................
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aWriteLock(m_mutex);
|
2006-02-07 09:24:07 +00:00
|
|
|
|
2005-03-21 12:27:42 +00:00
|
|
|
css::uno::Reference< css::document::XActionLockable > xLock(xTask, css::uno::UNO_QUERY);
|
2004-01-28 13:37:23 +00:00
|
|
|
if (!m_aTargetLock.setResource(xLock))
|
|
|
|
return css::uno::Reference< css::frame::XFrame >();
|
2006-02-07 09:24:07 +00:00
|
|
|
|
|
|
|
m_bReactivateControllerOnError = bReactivateOldControllerOnError;
|
2014-03-20 10:49:20 +01:00
|
|
|
aWriteLock.clear();
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE ..................................
|
|
|
|
|
2007-07-03 13:16:25 +00:00
|
|
|
// bring it to front ...
|
2014-04-04 15:53:21 +02:00
|
|
|
impl_makeFrameWindowVisible(xTask->getContainerWindow(), true);
|
2007-07-03 13:16:25 +00:00
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
return xTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadEnv::impl_reactForLoadingState()
|
|
|
|
throw(LoadEnvException, css::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
/*TODO reset action locks */
|
|
|
|
|
|
|
|
// SAFE -> ----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
|
|
|
if (m_bLoaded)
|
|
|
|
{
|
|
|
|
// Bring the new loaded document to front (if allowed!).
|
|
|
|
// Note: We show new created frames here only.
|
|
|
|
// We dont hide already visible frames here ...
|
2004-11-26 13:32:02 +00:00
|
|
|
css::uno::Reference< css::awt::XWindow > xWindow = m_xTargetFrame->getContainerWindow();
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bHidden = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN(), sal_False);
|
|
|
|
bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_MINIMIZED(), sal_False);
|
2004-01-28 13:37:23 +00:00
|
|
|
|
2004-07-23 10:08:28 +00:00
|
|
|
if (bMinimized)
|
|
|
|
{
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
|
2013-03-03 17:11:39 +01:00
|
|
|
// check for system window is necessary to guarantee correct pointer cast!
|
2004-07-23 10:08:28 +00:00
|
|
|
if (pWindow && pWindow->IsSystemWindow())
|
2014-10-01 15:16:01 +02:00
|
|
|
static_cast<WorkWindow*>(pWindow)->Minimize();
|
2004-07-23 10:08:28 +00:00
|
|
|
}
|
2012-10-11 10:11:26 +01:00
|
|
|
else if (!bHidden)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
2005-03-03 23:14:34 +00:00
|
|
|
// show frame ... if it's not still visible ...
|
|
|
|
// But do nothing if it's already visible!
|
2014-04-04 15:53:21 +02:00
|
|
|
impl_makeFrameWindowVisible(xWindow, false);
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
2004-02-26 09:39:12 +00:00
|
|
|
// Note: Only if an existing property "FrameName" is given by this media descriptor,
|
2013-09-26 10:02:26 +02:00
|
|
|
// it should be used. Otherwise we should do nothing. May be the outside code has already
|
2004-02-26 09:39:12 +00:00
|
|
|
// set a frame name on the target!
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::const_iterator pFrameName = m_lMediaDescriptor.find(utl::MediaDescriptor::PROP_FRAMENAME());
|
2004-02-26 09:39:12 +00:00
|
|
|
if (pFrameName != m_lMediaDescriptor.end())
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFrameName;
|
2004-02-26 09:39:12 +00:00
|
|
|
pFrameName->second >>= sFrameName;
|
2013-09-26 10:02:26 +02:00
|
|
|
// Check the name again. e.g. "_default" isn't allowed.
|
2004-02-26 09:39:12 +00:00
|
|
|
// On the other side "_beamer" is a valid name :-)
|
|
|
|
if (TargetHelper::isValidNameForFrame(sFrameName))
|
|
|
|
m_xTargetFrame->setName(sFrameName);
|
|
|
|
}
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
2009-09-18 10:15:03 +00:00
|
|
|
else if (m_bReactivateControllerOnError)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// Try to reactivate the old document (if any exists!)
|
|
|
|
css::uno::Reference< css::frame::XController > xOldDoc = m_xTargetFrame->getController();
|
|
|
|
// clear does not depend from reactivation state of a might existing old document!
|
2011-11-13 23:44:40 +01:00
|
|
|
// We must make sure, that a might following getTargetComponent() call does not return
|
2004-01-28 13:37:23 +00:00
|
|
|
// the old document!
|
|
|
|
m_xTargetFrame.clear();
|
|
|
|
if (xOldDoc.is())
|
|
|
|
{
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bReactivated = xOldDoc->suspend(sal_False);
|
2004-01-28 13:37:23 +00:00
|
|
|
if (!bReactivated)
|
|
|
|
throw LoadEnvException(LoadEnvException::ID_COULD_NOT_REACTIVATE_CONTROLLER);
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bReactivateControllerOnError = false;
|
2004-01-28 13:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-18 10:15:03 +00:00
|
|
|
else if (m_bCloseFrameOnError)
|
2004-01-28 13:37:23 +00:00
|
|
|
{
|
|
|
|
// close empty frames
|
|
|
|
css::uno::Reference< css::util::XCloseable > xCloseable (m_xTargetFrame, css::uno::UNO_QUERY);
|
|
|
|
css::uno::Reference< css::lang::XComponent > xDisposable(m_xTargetFrame, css::uno::UNO_QUERY);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (xCloseable.is())
|
|
|
|
xCloseable->close(sal_True);
|
|
|
|
else
|
|
|
|
if (xDisposable.is())
|
|
|
|
xDisposable->dispose();
|
|
|
|
}
|
|
|
|
catch(const css::util::CloseVetoException&)
|
|
|
|
{}
|
|
|
|
catch(const css::lang::DisposedException&)
|
|
|
|
{}
|
|
|
|
m_xTargetFrame.clear();
|
|
|
|
}
|
|
|
|
|
2004-06-10 12:21:50 +00:00
|
|
|
// This max force an implicit closing of our target frame ...
|
2010-11-05 10:31:15 +08:00
|
|
|
// e.g. in case close(sal_True) was called before and the frame
|
2004-06-10 12:21:50 +00:00
|
|
|
// kill itself if our external use-lock is released here!
|
2013-09-26 10:02:26 +02:00
|
|
|
// That's why we release this lock AFTER ALL OPERATIONS on this frame
|
|
|
|
// are finished. The frame itself must handle then
|
2004-06-10 12:21:50 +00:00
|
|
|
// this situation gracefully.
|
|
|
|
m_aTargetLock.freeResource();
|
|
|
|
|
|
|
|
// Last but not least :-)
|
|
|
|
// We have to clear the current media descriptor.
|
2013-09-26 10:02:26 +02:00
|
|
|
// Otherwise it hold a might existing stream open!
|
2004-06-10 12:21:50 +00:00
|
|
|
m_lMediaDescriptor.clear();
|
|
|
|
|
2009-09-18 10:15:03 +00:00
|
|
|
css::uno::Any aRequest;
|
|
|
|
bool bThrow = false;
|
2014-06-12 17:20:32 +02:00
|
|
|
if ( !m_bLoaded && m_pQuietInteraction.is() && m_pQuietInteraction->wasUsed() )
|
2009-09-18 10:15:03 +00:00
|
|
|
{
|
|
|
|
aRequest = m_pQuietInteraction->getRequest();
|
2014-06-12 17:20:32 +02:00
|
|
|
m_pQuietInteraction.clear();
|
2009-09-18 10:15:03 +00:00
|
|
|
bThrow = true;
|
|
|
|
}
|
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2009-09-18 10:15:03 +00:00
|
|
|
|
|
|
|
if (bThrow)
|
|
|
|
{
|
2010-01-22 22:22:41 +01:00
|
|
|
if ( aRequest.isExtractableTo( ::cppu::UnoType< css::uno::Exception >::get() ) )
|
2013-11-01 09:00:17 +01:00
|
|
|
throw LoadEnvException(
|
|
|
|
LoadEnvException::ID_GENERAL_ERROR, "interaction request",
|
|
|
|
aRequest);
|
2009-09-18 10:15:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
// <- SAFE ----------------------------------
|
|
|
|
}
|
|
|
|
|
2005-03-03 23:14:34 +00:00
|
|
|
void LoadEnv::impl_makeFrameWindowVisible(const css::uno::Reference< css::awt::XWindow >& xWindow ,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bForceToFront)
|
2005-03-03 23:14:34 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
// SAFE -> ----------------------------------
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2009-10-21 14:48:59 +00:00
|
|
|
// <- SAFE ----------------------------------
|
2005-03-03 23:14:34 +00:00
|
|
|
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
|
2009-10-21 14:48:59 +00:00
|
|
|
if ( pWindow )
|
|
|
|
{
|
2011-11-14 20:35:32 +01:00
|
|
|
bool const preview( m_lMediaDescriptor.getUnpackedValueOrDefault(
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::PROP_PREVIEW(), sal_False) );
|
2011-11-13 15:26:41 +01:00
|
|
|
|
2010-02-12 16:56:44 +01:00
|
|
|
bool bForceFrontAndFocus(false);
|
2011-11-13 15:26:41 +01:00
|
|
|
if ( !preview )
|
|
|
|
{
|
2011-11-14 20:35:32 +01:00
|
|
|
css::uno::Any const a =
|
|
|
|
::comphelper::ConfigurationHelper::readDirectKey(
|
2013-05-21 17:38:02 +02:00
|
|
|
xContext,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString("org.openoffice.Office.Common/View"),
|
|
|
|
OUString("NewDocumentHandling"),
|
|
|
|
OUString("ForceFocusAndToFront"),
|
2011-11-13 15:26:41 +01:00
|
|
|
::comphelper::ConfigurationHelper::E_READONLY);
|
|
|
|
a >>= bForceFrontAndFocus;
|
|
|
|
}
|
2009-10-21 14:48:59 +00:00
|
|
|
|
2010-06-07 13:31:53 +02:00
|
|
|
if( pWindow->IsVisible() && (bForceFrontAndFocus || bForceToFront) )
|
|
|
|
pWindow->ToTop();
|
|
|
|
else
|
2014-01-28 20:02:01 +01:00
|
|
|
pWindow->Show(true, (bForceFrontAndFocus || bForceToFront) ? SHOW_FOREGROUNDTASK : 0 );
|
2009-10-21 14:48:59 +00:00
|
|
|
}
|
2005-03-03 23:14:34 +00:00
|
|
|
}
|
|
|
|
|
2005-03-23 15:15:20 +00:00
|
|
|
void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
|
|
|
|
{
|
2014-11-03 14:03:54 +02:00
|
|
|
static const char PACKAGE_SETUP_MODULES[] = "/org.openoffice.Setup/Office/Factories";
|
2005-03-23 15:15:20 +00:00
|
|
|
|
|
|
|
// no window -> action not possible
|
|
|
|
if (!xWindow.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// window already visible -> do nothing! If we use a "recycle frame" for loading ...
|
|
|
|
// the current position and size must be used.
|
|
|
|
css::uno::Reference< css::awt::XWindow2 > xVisibleCheck(xWindow, css::uno::UNO_QUERY);
|
|
|
|
if (
|
|
|
|
(xVisibleCheck.is() ) &&
|
|
|
|
(xVisibleCheck->isVisible())
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
2005-04-22 12:31:01 +00:00
|
|
|
// SOLAR SAFE ->
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexClearableGuard aSolarGuard1;
|
2005-04-22 12:31:01 +00:00
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
|
2010-10-05 15:56:57 +01:00
|
|
|
if (!pWindow)
|
|
|
|
return;
|
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bSystemWindow = pWindow->IsSystemWindow();
|
|
|
|
bool bWorkWindow = (pWindow->GetType() == WINDOW_WORKWINDOW);
|
2005-03-23 15:15:20 +00:00
|
|
|
|
|
|
|
if (!bSystemWindow && !bWorkWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// dont overwrite this special state!
|
2014-10-01 15:16:01 +02:00
|
|
|
WorkWindow* pWorkWindow = static_cast<WorkWindow*>(pWindow);
|
2005-03-23 15:15:20 +00:00
|
|
|
if (pWorkWindow->IsMinimized())
|
|
|
|
return;
|
|
|
|
|
2010-10-14 22:09:00 -05:00
|
|
|
aSolarGuard1.clear();
|
2005-04-22 12:31:01 +00:00
|
|
|
// <- SOLAR SAFE
|
|
|
|
|
2005-03-23 15:15:20 +00:00
|
|
|
// SAFE ->
|
2014-03-20 10:49:20 +01:00
|
|
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
2005-03-23 15:15:20 +00:00
|
|
|
|
|
|
|
// no filter -> no module -> no persistent window state
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFilter = m_lMediaDescriptor.getUnpackedValueOrDefault(
|
2013-11-13 08:52:41 +01:00
|
|
|
utl::MediaDescriptor::PROP_FILTERNAME(),
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString());
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sFilter.isEmpty())
|
2005-03-23 15:15:20 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-21 17:38:02 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
|
2005-03-23 15:15:20 +00:00
|
|
|
|
2014-03-20 10:49:20 +01:00
|
|
|
aReadLock.clear();
|
2005-03-23 15:15:20 +00:00
|
|
|
// <- SAFE
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// retrieve the module name from the filter configuration
|
|
|
|
css::uno::Reference< css::container::XNameAccess > xFilterCfg(
|
2013-05-21 17:38:02 +02:00
|
|
|
xContext->getServiceManager()->createInstanceWithContext(SERVICENAME_FILTERFACTORY, xContext),
|
2005-03-23 15:15:20 +00:00
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
::comphelper::SequenceAsHashMap lProps (xFilterCfg->getByName(sFilter));
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sModule = lProps.getUnpackedValueOrDefault(FILTER_PROPNAME_DOCUMENTSERVICE, OUString());
|
2005-03-23 15:15:20 +00:00
|
|
|
|
|
|
|
// get access to the configuration of this office module
|
|
|
|
css::uno::Reference< css::container::XNameAccess > xModuleCfg(::comphelper::ConfigurationHelper::openConfig(
|
2013-05-21 17:38:02 +02:00
|
|
|
xContext,
|
2005-03-23 15:15:20 +00:00
|
|
|
PACKAGE_SETUP_MODULES,
|
|
|
|
::comphelper::ConfigurationHelper::E_READONLY),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
// read window state from the configuration
|
|
|
|
// and apply it on the window.
|
|
|
|
// Do nothing, if no configuration entry exists!
|
2014-04-06 19:36:08 +03:00
|
|
|
OUString sWindowState;
|
2009-09-08 04:57:32 +00:00
|
|
|
::comphelper::ConfigurationHelper::readRelativeKey(xModuleCfg, sModule, OFFICEFACTORY_PROPNAME_WINDOWATTRIBUTES) >>= sWindowState;
|
2011-12-26 14:20:50 -02:00
|
|
|
if (!sWindowState.isEmpty())
|
2005-04-22 12:31:01 +00:00
|
|
|
{
|
|
|
|
// SOLAR SAFE ->
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-04-22 12:31:01 +00:00
|
|
|
|
|
|
|
// We have to retrieve the window pointer again. Because nobody can guarantee
|
2013-09-26 10:02:26 +02:00
|
|
|
// that the XWindow was not disposed in between .-)
|
2005-04-22 12:31:01 +00:00
|
|
|
// But if we get a valid pointer we can be sure, that it's the system window pointer
|
2013-09-26 10:02:26 +02:00
|
|
|
// we already checked and used before. Because nobody recycle the same uno reference for
|
2005-04-22 12:31:01 +00:00
|
|
|
// a new internal c++ implementation ... hopefully .-))
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWindowCheck = VCLUnoHelper::GetWindow(xWindow);
|
2005-04-22 12:31:01 +00:00
|
|
|
if (! pWindowCheck)
|
|
|
|
return;
|
|
|
|
|
2014-10-01 15:16:01 +02:00
|
|
|
SystemWindow* pSystemWindow = static_cast<SystemWindow*>(pWindowCheck);
|
2013-04-07 12:06:47 +02:00
|
|
|
pSystemWindow->SetWindowState(OUStringToOString(sWindowState,RTL_TEXTENCODING_UTF8));
|
2005-04-22 12:31:01 +00:00
|
|
|
// <- SOLAR SAFE
|
|
|
|
}
|
2005-03-23 15:15:20 +00:00
|
|
|
}
|
2012-02-05 11:53:47 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2005-03-23 15:15:20 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
2004-01-28 13:37:23 +00:00
|
|
|
} // namespace framework
|
2004-08-02 16:45:48 +00:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|