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/+/202506
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna
2026-03-23 22:48:25 +01:00
parent 713bc94ca3
commit e0575ba229
2 changed files with 75 additions and 3 deletions
+62
View File
@@ -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
{
@@ -130,6 +156,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();
+13 -3
View File
@@ -641,8 +641,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);
@@ -652,7 +662,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,
@@ -661,7 +671,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(