diff options
Diffstat (limited to 'framework/source/loadenv/loadenv.cxx')
-rw-r--r-- | framework/source/loadenv/loadenv.cxx | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index 12cc84b7dab4..5871c56619ab 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -73,6 +73,7 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/util/XModifiable.hpp> +#include <utility> #include <vcl/window.hxx> #include <vcl/wrkwin.hxx> #include <vcl/syswin.hxx> @@ -84,15 +85,15 @@ #include <comphelper/configurationhelper.hxx> #include <rtl/bootstrap.hxx> #include <sal/log.hxx> -#include <vcl/errcode.hxx> +#include <comphelper/errcode.hxx> #include <vcl/svapp.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/profilezone.hxx> #include <classes/taskcreator.hxx> #include <tools/fileutil.hxx> -constexpr OUStringLiteral PROP_TYPES = u"Types"; -constexpr OUStringLiteral PROP_NAME = u"Name"; +constexpr OUString PROP_TYPES = u"Types"_ustr; +constexpr OUString PROP_NAME = u"Name"_ustr; namespace framework { @@ -104,7 +105,7 @@ class LoadEnvListener : public ::cppu::WeakImplHelper< css::frame::XLoadEventLis css::frame::XDispatchResultListener > { private: - osl::Mutex m_mutex; + std::mutex m_mutex; bool m_bWaitingResult; LoadEnv* m_pLoadEnv; @@ -130,8 +131,8 @@ class LoadEnvListener : public ::cppu::WeakImplHelper< css::frame::XLoadEventLis } -LoadEnv::LoadEnv(const css::uno::Reference< css::uno::XComponentContext >& xContext) - : m_xContext(xContext) +LoadEnv::LoadEnv(css::uno::Reference< css::uno::XComponentContext > xContext) + : m_xContext(std::move(xContext)) , m_nSearchFlags(0) , m_eFeature(LoadEnvFeatures::NONE) , m_eContentType(E_UNSUPPORTED_CONTENT) @@ -160,9 +161,8 @@ css::uno::Reference< css::lang::XComponent > LoadEnv::loadComponentFromURL(const LoadEnv aEnv(xContext); LoadEnvFeatures loadEnvFeatures = LoadEnvFeatures::WorkWithUI; - comphelper::NamedValueCollection aDescriptor( lArgs ); // tdf#118238 Only disable UI interaction when loading as hidden - if (aDescriptor.get("Hidden") == uno::Any(true) || Application::IsHeadlessModeEnabled()) + if (comphelper::NamedValueCollection::get(lArgs, u"Hidden") == uno::Any(true) || Application::IsHeadlessModeEnabled()) loadEnvFeatures = LoadEnvFeatures::NONE; aEnv.startLoading(sURL, @@ -295,6 +295,14 @@ void LoadEnv::startLoading(const OUString& sURL, const uno::Sequence<beans::Prop !m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN, false) && !m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW, false); + if( comphelper::LibreOfficeKit::isActive() && + m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_SILENT, false)) + { + rtl::Reference<QuietInteraction> pQuietInteraction = new QuietInteraction(); + uno::Reference<task::XInteractionHandler> xInteractionHandler(pQuietInteraction); + m_lMediaDescriptor[utl::MediaDescriptor::PROP_INTERACTIONHANDLER] <<= xInteractionHandler; + } + initializeUIDefaults(m_xContext, m_lMediaDescriptor, bUIMode, &m_pQuietInteraction); start(); @@ -314,7 +322,16 @@ void LoadEnv::initializeUIDefaults( const css::uno::Reference< css::uno::XCompon nUpdateMode = css::document::UpdateDocMode::ACCORDING_TO_CONFIG; try { - xInteractionHandler.set( css::task::InteractionHandler::createWithParent( i_rxContext, nullptr ), css::uno::UNO_QUERY_THROW ); + // tdf#154308 At least for the case the document is launched from the StartCenter, put that StartCenter as the + // parent for any dialogs that may appear during typedetection (once load starts a permanent frame will be set + // anyway and used as dialog parent, which will be this one if the startcenter was running) + css::uno::Reference<css::frame::XFramesSupplier> xSupplier = css::frame::Desktop::create(i_rxContext); + FrameListAnalyzer aTasksAnalyzer(xSupplier, css::uno::Reference<css::frame::XFrame>(), FrameAnalyzerFlags::BackingComponent); + css::uno::Reference<css::awt::XWindow> xDialogParent(aTasksAnalyzer.m_xBackingComponent ? + aTasksAnalyzer.m_xBackingComponent->getContainerWindow() : + nullptr); + + xInteractionHandler.set( css::task::InteractionHandler::createWithParent(i_rxContext, xDialogParent), css::uno::UNO_QUERY_THROW ); } catch(const css::uno::RuntimeException&) {throw;} catch(const css::uno::Exception& ) { } @@ -460,7 +477,7 @@ css::uno::Reference< css::lang::XComponent > LoadEnv::getTargetComponent() const void SAL_CALL LoadEnvListener::loadFinished(const css::uno::Reference< css::frame::XFrameLoader >&) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); if (m_bWaitingResult) m_pLoadEnv->impl_setResult(true); m_bWaitingResult = false; @@ -468,7 +485,7 @@ void SAL_CALL LoadEnvListener::loadFinished(const css::uno::Reference< css::fram void SAL_CALL LoadEnvListener::loadCancelled(const css::uno::Reference< css::frame::XFrameLoader >&) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); if (m_bWaitingResult) m_pLoadEnv->impl_setResult(false); m_bWaitingResult = false; @@ -476,7 +493,7 @@ void SAL_CALL LoadEnvListener::loadCancelled(const css::uno::Reference< css::fra void SAL_CALL LoadEnvListener::dispatchFinished(const css::frame::DispatchResultEvent& aEvent) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); if (!m_bWaitingResult) return; @@ -500,7 +517,7 @@ void SAL_CALL LoadEnvListener::dispatchFinished(const css::frame::DispatchResult void SAL_CALL LoadEnvListener::disposing(const css::lang::EventObject&) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); if (m_bWaitingResult) m_pLoadEnv->impl_setResult(false); m_bWaitingResult = false; @@ -624,7 +641,7 @@ LoadEnv::EContentType LoadEnv::classifyContent(const OUString& css::uno::Sequence< OUString > lTypesReg { sType }; css::uno::Sequence< css::beans::NamedValue > lQuery { - css::beans::NamedValue(PROP_TYPES, makeAny(lTypesReg)) + css::beans::NamedValue(PROP_TYPES, css::uno::Any(lTypesReg)) }; xLoaderFactory = css::frame::FrameLoaderFactory::create(xContext); @@ -673,7 +690,7 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip } } - if (aURL.isEmpty() || aURL.copy(0,8).equalsIgnoreAsciiCase("private:")) + if (aURL.isEmpty() || o3tl::equalsIgnoreAsciiCase(aURL.subView(0,8), u"private:")) return false; // TODO : Type must be set to be generic_Text (or any other type that @@ -681,8 +698,7 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip // hack. // depending on the experimental mode - uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); - if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext)) + if (!officecfg::Office::Common::Misc::ExperimentalMode::get()) { return false; } @@ -867,7 +883,7 @@ bool LoadEnv::impl_handleContent() // query css::uno::Sequence< OUString > lTypeReg { sType }; - css::uno::Sequence< css::beans::NamedValue > lQuery { { PROP_TYPES, css::uno::makeAny(lTypeReg) } }; + css::uno::Sequence< css::beans::NamedValue > lQuery { { PROP_TYPES, css::uno::Any(lTypeReg) } }; css::uno::Reference< css::container::XEnumeration > xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery); while(xSet->hasMoreElements()) @@ -914,7 +930,7 @@ bool LoadEnv::impl_furtherDocsAllowed() try { - std::optional<sal_Int32> x(officecfg::Office::Common::Misc::MaxOpenDocuments::get(xContext)); + std::optional<sal_Int32> x(officecfg::Office::Common::Misc::MaxOpenDocuments::get()); // NIL means: count of allowed documents = infinite ! // => return true @@ -1120,7 +1136,10 @@ bool LoadEnv::impl_loadContent() xHandler->initialize(aArguments); //show the frame as early as possible to make it the parent of any message dialogs if (!impl_filterHasInteractiveDialog()) - impl_makeFrameWindowVisible(xWindow, false); + { + impl_makeFrameWindowVisible(xWindow, shouldFocusAndToFront()); + m_bFocusedAndToFront = true; // no need to ask shouldFocusAndToFront second time + } } } @@ -1152,7 +1171,7 @@ bool LoadEnv::impl_loadContent() { // Set the URL on the frame itself, for the duration of the load, when it has no // controller. - xTargetFrameProps->setPropertyValue("URL", uno::makeAny(sURL)); + xTargetFrameProps->setPropertyValue("URL", uno::Any(sURL)); } bool bResult = xSyncLoader->load(lDescriptor, xTargetFrame); // react for the result here, so the outside waiting @@ -1205,7 +1224,7 @@ css::uno::Reference< css::uno::XInterface > LoadEnv::impl_searchLoader() css::uno::Sequence< OUString > lTypesReg { sType }; - css::uno::Sequence< css::beans::NamedValue > lQuery { { PROP_TYPES, css::uno::makeAny(lTypesReg) } }; + css::uno::Sequence< css::beans::NamedValue > lQuery { { PROP_TYPES, css::uno::Any(lTypesReg) } }; css::uno::Reference< css::container::XEnumeration > xSet = xLoaderFactory->createSubSetEnumerationByProperties(lQuery); while(xSet->hasMoreElements()) @@ -1409,15 +1428,13 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded() // if an optional jumpmark is given too. if (!m_aURL.Mark.isEmpty()) impl_jumpToMark(xResult, m_aURL); - - // bring it to front and make sure it's visible... - impl_makeFrameWindowVisible(xResult->getContainerWindow(), true); } return xResult; } -bool LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) const +// static +bool LoadEnv::impl_isFrameAlreadyUsedForLoading(const css::uno::Reference< css::frame::XFrame >& xFrame) { css::uno::Reference< css::document::XActionLockable > xLock(xFrame, css::uno::UNO_QUERY); @@ -1449,8 +1466,6 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget() { if (!impl_isFrameAlreadyUsedForLoading(aTasksAnalyzer.m_xBackingComponent)) { - // bring it to front... - impl_makeFrameWindowVisible(aTasksAnalyzer.m_xBackingComponent->getContainerWindow(), true); m_bReactivateControllerOnError = true; return aTasksAnalyzer.m_xBackingComponent; } @@ -1563,9 +1578,6 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchRecycleTarget() } // <- SAFE .................................. - // bring it to front ... - impl_makeFrameWindowVisible(xTask->getContainerWindow(), true); - return xTask; } @@ -1597,7 +1609,7 @@ void LoadEnv::impl_reactForLoadingState() { // show frame ... if it's not still visible ... // But do nothing if it's already visible! - impl_makeFrameWindowVisible(xWindow, false); + impl_makeFrameWindowVisible(xWindow, !m_bFocusedAndToFront && shouldFocusAndToFront()); } // Note: Only if an existing property "FrameName" is given by this media descriptor, @@ -1684,33 +1696,27 @@ void LoadEnv::impl_reactForLoadingState() // <- SAFE ---------------------------------- } +bool LoadEnv::shouldFocusAndToFront() const +{ + bool const preview( + m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW, false)); + return !preview + && officecfg::Office::Common::View::NewDocumentHandling::ForceFocusAndToFront::get(); +} + +// static void LoadEnv::impl_makeFrameWindowVisible(const css::uno::Reference< css::awt::XWindow >& xWindow , bool bForceToFront) { - // SAFE -> ---------------------------------- - osl::ClearableMutexGuard aReadLock(m_mutex); - css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext; - aReadLock.clear(); - // <- SAFE ---------------------------------- - SolarMutexGuard aSolarGuard; VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow); if ( !pWindow ) return; - bool const preview( m_lMediaDescriptor.getUnpackedValueOrDefault( - utl::MediaDescriptor::PROP_PREVIEW, false) ); - - bool bForceFrontAndFocus(false); - if ( !preview ) - { - bForceFrontAndFocus = officecfg::Office::Common::View::NewDocumentHandling::ForceFocusAndToFront::get(xContext); - } - - if( pWindow->IsVisible() && (bForceFrontAndFocus || bForceToFront) ) + if (pWindow->IsVisible() && bForceToFront) pWindow->ToTop( ToTopFlags::RestoreWhenMin | ToTopFlags::ForegroundTask ); else - pWindow->Show(true, (bForceFrontAndFocus || bForceToFront) ? ShowFlags::ForegroundTask : ShowFlags::NONE ); + pWindow->Show(true, bForceToFront ? ShowFlags::ForegroundTask : ShowFlags::NONE); } void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow) @@ -1774,7 +1780,7 @@ void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::aw OUString sModule = lProps.getUnpackedValueOrDefault(FILTER_PROPNAME_ASCII_DOCUMENTSERVICE, OUString()); // get access to the configuration of this office module - css::uno::Reference< css::container::XNameAccess > xModuleCfg(officecfg::Setup::Office::Factories::get(xContext)); + css::uno::Reference< css::container::XNameAccess > xModuleCfg(officecfg::Setup::Office::Factories::get()); // read window state from the configuration // and apply it on the window. @@ -1800,7 +1806,7 @@ void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::aw return; SystemWindow* pSystemWindow = static_cast<SystemWindow*>(pWindowCheck.get()); - pSystemWindow->SetWindowState(OUStringToOString(sWindowState,RTL_TEXTENCODING_UTF8)); + pSystemWindow->SetWindowState(sWindowState); // <- SOLAR SAFE } } |