desktop/qa/data/validity.ods                |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   78 ++++++++++++++++++++++++++++
 sc/source/ui/view/gridwin.cxx               |    4 +
 3 files changed, 82 insertions(+)

New commits:
commit a54a0e1906e35cbd0c812381704942ace24597dc
Author:     Gökay Şatır <[email protected]>
AuthorDate: Tue Dec 24 11:38:39 2024 +0300
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Jan 3 12:05:13 2025 +0100

    cool#10794 Test for: Don't open validity dropdown in readOnly mode.
    
    Issue: In readonly mode, validity dropdown is still usable.
    
    There are 2 tests here. 1 is to ensure that dropdown opens and it also 
exists as an example on dropdown events.
    The other is to ensure that dropdown is not opened in readonly mode.
    
    Signed-off-by: Gökay Şatır <[email protected]>
    Change-Id: Id73c4421454af2af4f306925d6c628f776ecd2d9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179303
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179697
    Tested-by: Jenkins

diff --git a/desktop/qa/data/validity.ods b/desktop/qa/data/validity.ods
new file mode 100644
index 000000000000..9f9677242ff0
Binary files /dev/null and b/desktop/qa/data/validity.ods differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 7bca2926e948..66b29c4cd1aa 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -193,6 +193,8 @@ public:
     void testCommentsCallbacksWriter();
     void testCommentsAddEditDeleteDraw();
     void testCommentsInReadOnlyMode();
+    void testCalcValidityDropdown();
+    void testCalcValidityDropdownInReadonlyMode();
     void testRunMacro();
     void testExtractParameter();
     void testGetSignatureState_NonSigned();
@@ -264,6 +266,8 @@ public:
     CPPUNIT_TEST(testCommentsCallbacksWriter);
     CPPUNIT_TEST(testCommentsAddEditDeleteDraw);
     CPPUNIT_TEST(testCommentsInReadOnlyMode);
+    CPPUNIT_TEST(testCalcValidityDropdown);
+    CPPUNIT_TEST(testCalcValidityDropdownInReadonlyMode);
     CPPUNIT_TEST(testRunMacro);
     CPPUNIT_TEST(testExtractParameter);
     CPPUNIT_TEST(testGetSignatureState_Signed);
@@ -2130,6 +2134,7 @@ class ViewCallback
     int mnView;
 public:
     OString m_aCellFormula;
+    boost::property_tree::ptree m_JSONDialog;
     int m_nTableSelectionCount;
     int m_nColorPaletteCallbackCount = 0;
     bool m_bEmptyTableSelection;
@@ -2214,6 +2219,13 @@ public:
             ++m_nColorPaletteCallbackCount;
         }
         break;
+        case LOK_CALLBACK_JSDIALOG:
+        {
+            m_JSONDialog.clear();
+            std::stringstream aStream(pPayload);
+            boost::property_tree::read_json(aStream, m_JSONDialog);
+        }
+        break;
         }
     }
 };
@@ -2736,6 +2748,72 @@ void DesktopLOKTest::testCommentsInReadOnlyMode()
     //CPPUNIT_ASSERT_EQUAL(nCommentId, 
aView.m_aCommentCallbackResult.get<int>("id"));
 }
 
+void DesktopLOKTest::testCalcValidityDropdown()
+{
+    LibLODocument_Impl* pDocument = loadDoc("validity.ods");
+    Scheduler::ProcessEventsToIdle();
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    Scheduler::ProcessEventsToIdle();
+
+    ViewCallback aView(pDocument);
+    Scheduler::ProcessEventsToIdle();
+
+    // Select row 1 from column 1.
+    pDocument->pClass->postMouseEvent(pDocument, 
LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1000, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+    pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 
1000, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+
+    // Open dropdown.
+    pDocument->pClass->postMouseEvent(pDocument, 
LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1380, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+    pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 
1380, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+
+    // Select some value from dropdown.
+    pDocument->pClass->sendDialogEvent(pDocument, 
aView.m_JSONDialog.get_child("id").get_value<int>(), "{\"id\":\"list\", 
\"cmd\": \"select\", \"data\": \"3\", \"type\": \"treeview\"}");
+    Scheduler::ProcessEventsToIdle();
+
+    // Activate the selected value.
+    pDocument->pClass->sendDialogEvent(pDocument, 
aView.m_JSONDialog.get_child("id").get_value<int>(), "{\"id\":\"list\", 
\"cmd\": \"activate\", \"data\": \"3\", \"type\": \"treeview\"}");
+    Scheduler::ProcessEventsToIdle();
+
+    // Check the content of the current cell. The selected value of the 
dropdown was 1. It should be 4 now.
+    char* pCellContent = pDocument->pClass->getTextSelection(pDocument, 
"text/plain;charset=utf-8", nullptr);
+    CPPUNIT_ASSERT_EQUAL("4"_ostr, OString(pCellContent));
+    free(pCellContent);
+}
+
+void DesktopLOKTest::testCalcValidityDropdownInReadonlyMode()
+{
+    LibLODocument_Impl* pDocument = loadDoc("validity.ods");
+    Scheduler::ProcessEventsToIdle();
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    Scheduler::ProcessEventsToIdle();
+
+    ViewCallback aView(pDocument);
+    Scheduler::ProcessEventsToIdle();
+
+    int viewId = pDocument->m_pDocumentClass->getView(pDocument);
+    SfxLokHelper::setViewReadOnly(viewId, true);
+    Scheduler::ProcessEventsToIdle();
+
+    // Select row 1 from column 1.
+    pDocument->pClass->postMouseEvent(pDocument, 
LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1000, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+    pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 
1000, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+
+    // Attempt to open dropdown.
+    pDocument->pClass->postMouseEvent(pDocument, 
LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1380, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+    pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 
1380, 150, 1, 1, 0);
+    Scheduler::ProcessEventsToIdle();
+
+    // Dropdown should not open in readonly mode.
+    CPPUNIT_ASSERT_EQUAL(true, aView.m_JSONDialog.empty());
+}
+
 void DesktopLOKTest::testRunMacro()
 {
     LibLibreOffice_Impl aOffice;
commit 223a8291a649ab462fad23b682ec9a014cf8d6ed
Author:     Gökay Şatır <[email protected]>
AuthorDate: Thu Dec 12 19:28:47 2024 +0300
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Jan 3 12:05:04 2025 +0100

    cool#10794 Don't open validity dropdown in readOnly mode.
    
    Issue: In readonly mode, validity dropdown is still usable.
    
    Since the action is not performed via an uno command but event handling 
(function name is also: HandleMouseButtonDown), we need to add a guard to event 
handler.
    
    This issue is online only. Desktop view doesn't have the issue.
    
    Signed-off-by: Gökay Şatır <[email protected]>
    Change-Id: Ic0883d610f484cbc2b777200333e6ae5d14f52d4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178378
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179696
    Tested-by: Jenkins

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 2a73bc1857fa..eb7cbb2e27a7 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2127,6 +2127,10 @@ void ScGridWindow::HandleMouseButtonDown( const 
MouseEvent& rMEvt, MouseEventSta
                 if (!bWasMouseCaptured && IsMouseCaptured())
                     ReleaseMouse();
 
+                const bool lokReadOnly = 
comphelper::LibreOfficeKit::isActive() && pViewSh->IsLokReadOnlyView();
+                if (lokReadOnly)
+                    return; // Return as if the action was performed, so the 
flow is not affected.
+
                 LaunchDataSelectMenu( aListValPos.Col(), aListValPos.Row() );
 
                 nMouseStatus = SC_GM_FILTER;    // not set in 
DoAutoFilterMenue for bDataSelect

Reply via email to