desktop/qa/desktop_lib/test_desktop_lib.cxx |   18 +++++++-----------
 desktop/source/lib/init.cxx                 |   15 +++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h     |    3 +++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   10 ++++++++++
 include/sfx2/viewsh.hxx                     |    4 ++++
 sw/source/core/view/viewsh.cxx              |    4 ++--
 6 files changed, 41 insertions(+), 13 deletions(-)

New commits:
commit 97d32edf39e9d64866d8cee6ab8b5c947c6e18db
Author:     Gökay Şatır <gokaysa...@gmail.com>
AuthorDate: Fri Feb 16 08:43:14 2024 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Mar 7 15:44:29 2024 +0100

    Collaborative editing with readonly and edit views.
    
    We can have both readOnly and editor views at the same time while 
collaboratively editing a document.
    Our current solution is to disable any command if the user's view is 
readonly.
    We want to have a closer behaviour to desktop app with readonly views.
    For this purpose, we are allowing more interactions from online server to 
core side.
    We also need to filter out the events like the core side readonly view do 
(next commit).
    This commit initiates the readonly view infrastructure.
    
    The patches previous commit reverts were an example of how we disable 
things in readonly mode. We needed to open a window for getting hyperlink 
information.
    With this patch, we try to separate the edit and readonly view modes on 
core side.
    
    More notes:
    
    We need "&& !comphelper::LibreOfficeKit::isActive()" or it falls into an 
endless loop with this patch.
    When we disable editing on a browser, almost all user actions are disabled.
    
    (cherry picked from commit 81dae2ca5187bd24aea0befb099a5b53535b5d03)
    
    Change-Id: Ia25368dd8065206ec6b4b83eb2f685531110cc78
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164527
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 87afe69166a8..1239af480598 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3668,22 +3668,18 @@ void DesktopLOKTest::testABI()
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct 
_LibreOfficeKitDocumentClass, sendFormFieldEvent));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), offsetof(struct 
_LibreOfficeKitDocumentClass, setBlockedCommandList));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct 
_LibreOfficeKitDocumentClass, renderSearchResult));
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(64),
-                         offsetof(struct _LibreOfficeKitDocumentClass, 
sendContentControlEvent));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), offsetof(struct 
_LibreOfficeKitDocumentClass, sendContentControlEvent));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), offsetof(struct 
_LibreOfficeKitDocumentClass, getSelectionTypeAndText));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(66), offsetof(struct 
_LibreOfficeKitDocumentClass, getDataArea));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(67), offsetof(struct 
_LibreOfficeKitDocumentClass, getEditMode));
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(68),
-                         offsetof(struct _LibreOfficeKitDocumentClass, 
setViewTimezone));
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(69),
-                         offsetof(struct _LibreOfficeKitDocumentClass, 
setAccessibilityState));
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(70),
-                         offsetof(struct _LibreOfficeKitDocumentClass, 
getA11yFocusedParagraph));
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(71),
-                         offsetof(struct _LibreOfficeKitDocumentClass, 
getA11yCaretPosition));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(68), offsetof(struct 
_LibreOfficeKitDocumentClass, setViewTimezone));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(69), offsetof(struct 
_LibreOfficeKitDocumentClass, setAccessibilityState));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(70), offsetof(struct 
_LibreOfficeKitDocumentClass, getA11yFocusedParagraph));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(71), offsetof(struct 
_LibreOfficeKitDocumentClass, getA11yCaretPosition));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(72), offsetof(struct 
_LibreOfficeKitDocumentClass, setViewReadOnly));
 
     // As above
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(72), sizeof(struct 
_LibreOfficeKitDocumentClass));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(73), sizeof(struct 
_LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 92f3d52affef..6d221ec84418 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1291,6 +1291,8 @@ static void 
doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const cha
 
 static void doc_setViewTimezone(LibreOfficeKitDocument* pThis, int nId, const 
char* timezone);
 
+static void doc_setViewReadOnly(LibreOfficeKitDocument* pThis, int nId, const 
bool readonly);
+
 static void doc_setAccessibilityState(LibreOfficeKitDocument* pThis, int nId, 
bool bEnabled);
 
 static char* doc_getA11yFocusedParagraph(LibreOfficeKitDocument* pThis);
@@ -1489,6 +1491,8 @@ LibLODocument_Impl::LibLODocument_Impl(uno::Reference 
<css::lang::XComponent> xC
         m_pDocumentClass->getA11yFocusedParagraph = 
doc_getA11yFocusedParagraph;
         m_pDocumentClass->getA11yCaretPosition = doc_getA11yCaretPosition;
 
+        m_pDocumentClass->setViewReadOnly = doc_setViewReadOnly;
+
         gDocumentClass = m_pDocumentClass;
     }
     pClass = m_pDocumentClass.get();
@@ -7192,6 +7196,17 @@ static void doc_setViewTimezone(SAL_UNUSED_PARAMETER 
LibreOfficeKitDocument* /*p
     }
 }
 
+static void doc_setViewReadOnly(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* 
pThis, int nId, const bool readOnly)
+{
+    comphelper::ProfileZone aZone("doc_setViewReadOnly");
+
+    SolarMutexGuard aGuard;
+    SetLastExceptionMsg();
+
+    doc_setView(pThis, nId);
+    SfxViewShell::Current()->SetLokReadOnlyView(readOnly);
+}
+
 static void doc_setAccessibilityState(SAL_UNUSED_PARAMETER 
LibreOfficeKitDocument* pThis, int nId, bool nEnabled)
 {
     SolarMutexGuard aGuard;
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index 6d446ab5aa4c..b28bae7e1ebc 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -514,6 +514,9 @@ struct _LibreOfficeKitDocumentClass
     /// @see lok::Document::getA11yCaretPosition.
     int (*getA11yCaretPosition) (LibreOfficeKitDocument* pThis);
 
+    /// @see lok::Document::setViewReadOnly().
+    void (*setViewReadOnly) (LibreOfficeKitDocument* pThis, int nId, const 
bool readOnly);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx 
b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 4c943a441c0a..4bf818fad747 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -859,6 +859,16 @@ public:
         mpDoc->pClass->setViewTimezone(mpDoc, nId, timezone);
     }
 
+    /** Set if the view should be treated as readonly or not.
+     *
+     * @param nId view ID
+     * @param readOnly
+    */
+    void setViewReadOnly(int nId, const bool readOnly)
+    {
+        mpDoc->pClass->setViewReadOnly(mpDoc, nId, readOnly);
+    }
+
     /**
      * Enable/Disable accessibility support for the window with the specified 
nId.
      *
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 805b7ee7893a..b52b8b520992 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -221,6 +221,7 @@ private:
 
     LOKDocumentFocusListener& GetLOKDocumentFocusListener();
     const LOKDocumentFocusListener& GetLOKDocumentFocusListener() const;
+    bool                        lokReadOnlyView = false; // When true, this is 
a LOK readonly view.
 
 public:
 
@@ -244,6 +245,9 @@ public:
     void                        JumpToMark( const OUString& rMark );
     void                        VisAreaChanged();
 
+    void                        SetLokReadOnlyView(bool readOnlyView) { 
lokReadOnlyView = readOnlyView; };
+    bool                        IsLokReadOnlyView() const { return 
lokReadOnlyView; };
+
     // Misc
 
     /**
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 75a38aeff994..7f048409bc02 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -2498,11 +2498,11 @@ void SwViewShell::SetReadonlyOption(bool bSet)
     {
         StartAction();
         Reformat();
-        if ( GetWin() )
+        if ( GetWin() && !comphelper::LibreOfficeKit::isActive() )
             GetWin()->Invalidate();
         EndAction();
     }
-    else if ( GetWin() )
+    else if ( GetWin() && !comphelper::LibreOfficeKit::isActive() )
         GetWin()->Invalidate();
 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
     if( Imp()->IsAccessible() )

Reply via email to