officecfg/registry/schema/org/openoffice/Office/Common.xcs | 6 ++++++ sfx2/source/dialog/backingwindow.cxx | 13 +++++++++++++ sfx2/source/doc/docfile.cxx | 4 ++++ sfx2/source/doc/objmisc.cxx | 3 ++- sfx2/source/view/frmload.cxx | 5 +++++ sfx2/source/view/viewfrm.cxx | 6 ++++++ 6 files changed, 36 insertions(+), 1 deletion(-)
New commits: commit 3a3ee9915947940b509f28c1d74fd2b49ffd709c Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Dec 6 00:55:59 2024 +0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Dec 9 14:27:37 2024 +0100 tdf#62845: Introduce an application-wide viewer mode Using the new 'ViewerAppMode' expert setting, the UI should disable all the edit controls; all options to create new content (including new documents); i.e., work as a view-only application. This change: 1. Introduces the setting. 2. Checks it in SfxMedium::IsReadOnly, making sure that all documents always have read-only medium. 3. Checks it in SfxFrameLoader_Impl::load, to prevent creation of new documents. 4. Checks it in SfxObjectShell::isEditDocLocked, to prevent entering edit mode. 5. Checks it in BackingWindow::checkInstalledModules, to hide buttons that create new documents. 6. Checks it in SfxViewFrame methods, to avoid showing "readonly" and "macros" infobars. Change-Id: Iaeeb8aab16db83ebdf500fd2bca8b8a9ac2180ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178007 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index b4bd480f4152..f3555068dd46 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -5551,6 +5551,12 @@ </info> <value>true</value> </prop> + <prop oor:name="ViewerAppMode" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Open all files in read-only mode</desc> + </info> + <value>false</value> + </prop> </group> <group oor:name="Forms"> <info> diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx index fb229f0f3f4a..12648c167253 100644 --- a/sfx2/source/dialog/backingwindow.cxx +++ b/sfx2/source/dialog/backingwindow.cxx @@ -404,6 +404,19 @@ void BackingWindow::initializeLocalView() void BackingWindow::checkInstalledModules() { + if (officecfg::Office::Common::Misc::ViewerAppMode::get()) + { + mxTemplateButton->set_visible(false); + mxCreateLabel->set_visible(false); + mxWriterAllButton->set_visible(false); + mxCalcAllButton->set_visible(false); + mxImpressAllButton->set_visible(false); + mxDrawAllButton->set_visible(false); + mxMathAllButton->set_visible(false); + mxDBAllButton->set_visible(false); + return; + } + SvtModuleOptions aModuleOpt; mxWriterAllButton->set_sensitive( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::WRITER )); diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index bbeff77e3b70..f4796d00955d 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3959,6 +3959,10 @@ void SfxMedium::SaveVersionList_Impl() bool SfxMedium::IsReadOnly() const { + // Application-wide read-only mode first + if (officecfg::Office::Common::Misc::ViewerAppMode::get()) + return true; + // a) ReadOnly filter can't produce read/write contents! bool bReadOnly = pImpl->m_pFilter && (pImpl->m_pFilter->GetFilterFlags() & SfxFilterFlags::OPENREADONLY); diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index c6696c004e29..d7b2087fe3e2 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -2019,7 +2019,8 @@ bool SfxObjectShell::isEditDocLocked() const Reference<XModel3> xModel = GetModel(); if (!xModel.is()) return false; - if (!officecfg::Office::Common::Misc::AllowEditReadonlyDocs::get()) + if (officecfg::Office::Common::Misc::ViewerAppMode::get() + || !officecfg::Office::Common::Misc::AllowEditReadonlyDocs::get()) return true; return comphelper::NamedValueCollection::getOrDefault(xModel->getArgs2( { "LockEditDoc" } ), u"LockEditDoc", false); } diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx index 7f58a397ccd3..99a06d12f269 100644 --- a/sfx2/source/view/frmload.cxx +++ b/sfx2/source/view/frmload.cxx @@ -53,6 +53,7 @@ #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> #include <framework/interaction.hxx> +#include <officecfg/Office/Common.hxx> #include <rtl/ref.hxx> #include <sal/log.hxx> #include <svl/eitem.hxx> @@ -626,6 +627,10 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rA // check for factory URLs to create a new doc, instead of loading one const OUString sURL = aDescriptor.getOrDefault( "URL", OUString() ); const bool bIsFactoryURL = sURL.startsWith( "private:factory/" ); + + if (bIsFactoryURL && officecfg::Office::Common::Misc::ViewerAppMode::get()) + return false; + std::shared_ptr<const SfxFilter> pEmptyURLFilter; bool bInitNewModel = bIsFactoryURL; const bool bIsDefault = bIsFactoryURL && !bExternalModel; diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index d3b62b6b1b03..05202e85f57b 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1263,6 +1263,9 @@ const SvBorder& SfxViewFrame::GetBorderPixelImpl() const void SfxViewFrame::AppendReadOnlyInfobar() { + if (officecfg::Office::Common::Misc::ViewerAppMode::get()) + return; + bool bSignPDF = m_xObjSh->IsSignPDF(); bool bSignWithCert = false; if (bSignPDF) @@ -1341,6 +1344,9 @@ void SfxViewFrame::HandleSecurityInfobar(const OUString& sSecondaryMessage) void SfxViewFrame::AppendContainsMacrosInfobar() { + if (officecfg::Office::Common::Misc::ViewerAppMode::get()) + return; + SfxObjectShell_Impl* pObjImpl = m_xObjSh->Get_Impl(); // what's the difference between pObjImpl->documentStorageHasMacros() and pObjImpl->aMacroMode.hasMacroLibrary() ?