sd/qa/ui/func/func.cxx | 62 +++++++++++++++++++++++++++++++++++++++++++ sd/source/ui/func/fudraw.cxx | 16 +++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-)
New commits: commit 57068786d24ef00fc2996bc9d12d56b530bb70f0 Author: Miklos Vajna <[email protected]> AuthorDate: Fri Mar 20 15:02:06 2026 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Mon Mar 23 11:14:00 2026 +0100 cool#15133 sd: fix missing LOK read-only handling in FuDraw::DoubleClick() Regression from online.git commit 3cf8a2f1f161270fb0a85863bea1d5277e92eed3 (cool#10630 doc electronic sign: fix outgoing mouse messages on 2nd page, 2025-01-27), click somewhere on the 2nd page of a PDF file in LOK mode, the view jumps to page 1, while nothing should happen. This "worked" previously because the JS client had a bug and we sent an out-of-page coordinate for the mouse click, so nothing happened, while now it started text edit on the only graphic object on the page. One big image for each page is the expected model for pdfium-based import result, but adding text to images in a read-only view is not wanted. Fix the problem by improving sd::FuDraw::DoubleClick() to check for LokReadOnlyView next to the existing ReadOnly, which should improve things in general for multiple LOK views where some of them are read-only and others are read-write. Change-Id: Id862c0e143366f7f6fec07576ef5bad8729a0a72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202252 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/sd/qa/ui/func/func.cxx b/sd/qa/ui/func/func.cxx index 6ae13f1baa1f..d9687940f57d 100644 --- a/sd/qa/ui/func/func.cxx +++ b/sd/qa/ui/func/func.cxx @@ -15,6 +15,13 @@ #include <comphelper/sequenceashashmap.hxx> #include <comphelper/propertyvalue.hxx> #include <vcl/scheduler.hxx> +#include <osl/process.h> +#include <comphelper/lok.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <sfx2/viewsh.hxx> +#include <svx/svdview.hxx> +#include <o3tl/unit_conversion.hxx> +#include <vcl/pdfread.hxx> #include <DrawDocShell.hxx> #include <ViewShell.hxx> @@ -25,6 +32,25 @@ using namespace com::sun::star; namespace { +struct UsePdfium +{ + // We need to enable PDFium import (and make sure to disable after the test) + bool bResetEnvVar = false; + UsePdfium() + { + if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr) + { + bResetEnvVar = true; + osl_setEnvironment(u"LO_IMPORT_USE_PDFIUM"_ustr.pData, u"1"_ustr.pData); + } + } + ~UsePdfium() + { + if (bResetEnvVar) + osl_clearEnvironment(u"LO_IMPORT_USE_PDFIUM"_ustr.pData); + }; +}; + /// Covers sd/source/ui/func/ fixes. class Test : public SdModelTestBase { @@ -128,6 +154,42 @@ CPPUNIT_TEST_FIXTURE(Test, testNoneToLibraryBullet) // i.e. the bullet char was the default, not the selected one. CPPUNIT_ASSERT_EQUAL(u"\u25CB"_ustr, aBulletChar); } + +CPPUNIT_TEST_FIXTURE(Test, testPDFReadLOKOnlyTextEdit) +{ + comphelper::LibreOfficeKit::setActive(); + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); + if (!pPdfium) + { + return; + } + + // Given a PDF loaded in LOK read-only mode: + UsePdfium aGuard; + loadFromFile(u"pdf/sample.pdf"); + auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + SfxViewShell* pSfxViewShell = SfxViewShell::Current(); + CPPUNIT_ASSERT(pSfxViewShell); + pSfxViewShell->SetLokReadOnlyView(true); + + // When double-clicking at the page center: + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + SdrView* pView = pViewShell->GetView(); + SdPage* pPage = pViewShell->GetActualPage(); + Size aPageSize = pPage->GetSize(); + auto nCenterX = o3tl::toTwips(aPageSize.Width() / 2, o3tl::Length::mm100); + auto nCenterY = o3tl::toTwips(aPageSize.Height() / 2, o3tl::Length::mm100); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, nCenterX, nCenterY, 2, + MOUSE_LEFT, 0); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, nCenterX, nCenterY, 2, + MOUSE_LEFT, 0); + Scheduler::ProcessEventsToIdle(); + + // Then text edit should not be active in read-only mode: + // Without the accompanying fix in place, this test would have failed, per-doc read-only and + // per-view read-only worked differently. + CPPUNIT_ASSERT(!pView->IsTextEdit()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/ui/func/fudraw.cxx b/sd/source/ui/func/fudraw.cxx index bb1811ab037f..4f24ac9a682c 100644 --- a/sd/source/ui/func/fudraw.cxx +++ b/sd/source/ui/func/fudraw.cxx @@ -640,8 +640,18 @@ void FuDraw::DoubleClick(const MouseEvent& rMEvt) SdrInventor nInv = pObj->GetObjInventor(); SdrObjKind nSdrObjKind = pObj->GetObjIdentifier(); + bool bReadOnly = mpDocSh->IsReadOnly(); + if (!bReadOnly) + { + SfxViewShell* pViewShell = mrViewShell.GetViewShell(); + if (pViewShell) + { + bReadOnly = pViewShell->IsLokReadOnlyView(); + } + } + if (nInv == SdrInventor::Default && nSdrObjKind == SdrObjKind::OLE2 - && !mpDocSh->IsReadOnly()) + && !bReadOnly) { // activate OLE-object SfxInt16Item aItem(SID_OBJECT, 0); @@ -651,7 +661,7 @@ void FuDraw::DoubleClick(const MouseEvent& rMEvt) { &aItem }); } else if (nInv == SdrInventor::Default && nSdrObjKind == SdrObjKind::Graphic - && pObj->IsEmptyPresObj() && !mpDocSh->IsReadOnly()) + && pObj->IsEmptyPresObj() && !bReadOnly) { mrViewShell.GetViewFrame()-> GetDispatcher()->Execute( SID_INSERT_GRAPHIC, @@ -660,7 +670,7 @@ void FuDraw::DoubleClick(const MouseEvent& rMEvt) else if ( ( DynCastSdrTextObj( pObj ) != nullptr || dynamic_cast< const SdrObjGroup *>( pObj ) != nullptr ) && !SdModule::get()->GetWaterCan() && mrViewShell.GetFrameView()->IsDoubleClickTextEdit() && - !mpDocSh->IsReadOnly()) + !bReadOnly) { SfxUInt16Item aItem(SID_TEXTEDIT, 2); mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
