From c60598390725cc23dc1401beec057f1386226ac8 Mon Sep 17 00:00:00 2001 From: Gökay Şatır Date: Thu, 22 Feb 2024 13:54:06 +0300 Subject: Moving parts of readonly checks from model to view. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary for what's done with this commit: init.cxx * Add guards for modify commands. viewsh: * Add "IsCurrentLokViewReadOnly" for ease of use. unocitm: * Add guard for modify comamnds dispatch.cxx * Implement readonlyview. objmisc: * Modify IsReadOnlyUI check for LokReadOnly view. svx.sdi: * Disable TableChangeCurrentBorderPosition command for readOnly views. sw-editwin: * Treat mouse moves as readonly when the view is LokReadOnly. gridwin: * For autofilter. impedit2, inputhdl: * For text input. svdedtc: * For sdr object dragging. Signed-off-by: Gökay Şatır Change-Id: I71fc353976256bce22042bbb6042ee464b65cc13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163731 Tested-by: Jenkins CollaboraOffice Reviewed-by: Gökay ŞATIR --- desktop/source/lib/init.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'desktop') diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 939fe2afc09f..586d9b4d84cc 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -4726,6 +4726,10 @@ static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsig static void doc_removeTextContext(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nCharBefore, int nCharAfter) { SolarMutexGuard aGuard; + + if (SfxViewShell::IsCurrentLokViewReadOnly()) + return; + VclPtr pWindow; if (nLOKWindowId == 0) { @@ -5107,6 +5111,23 @@ void LibLibreOffice_Impl::dumpState(rtl::OStringBuffer &rState) vcl::lok::dumpState(rState); } +// We have special handling for some uno commands and it seems we need to check for readonly state. +static bool isCommandAllowed(OUString& command) { + static constexpr OUString nonAllowedList[] = { u".uno:Save"_ustr, u".uno:TransformDialog"_ustr, u".uno:SidebarShow"_ustr, u".uno:SidebarHide"_ustr }; + + if (!SfxViewShell::IsCurrentLokViewReadOnly()) + return true; + else + { + for (size_t i = 0; i < std::size(nonAllowedList); i++) + { + if (nonAllowedList[i] == command) + return false; + } + return true; + } +} + static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished) { comphelper::ProfileZone aZone("doc_postUnoCommand"); @@ -5116,6 +5137,10 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma SfxObjectShell* pDocSh = SfxObjectShell::Current(); OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8); + + if (!isCommandAllowed(aCommand)) + return; + LibLODocument_Impl* pDocument = static_cast(pThis); std::vector aPropertyValuesVector(jsonToPropertyValuesVector(pArguments)); @@ -7167,6 +7192,9 @@ static void doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const cha return; } + if (SfxViewShell::IsCurrentLokViewReadOnly()) + return; + StringMap aMap(jsdialog::jsonToStringMap(pArguments)); ITiledRenderable* pDoc = getTiledRenderable(pThis); if (!pDoc) -- cgit