sd/qa/unit/tiledrendering/tiledrendering.cxx              |   26 ++++++++++++++
 sd/qa/unit/tiledrendering/tiledrenderingmodeltestbase.cxx |    2 +
 sd/source/ui/view/drviewsg.cxx                            |   16 ++++++++
 3 files changed, 44 insertions(+)

New commits:
commit 9d9c24328cef503f999bf3a5475743e87a3aff5a
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Tue Sep 24 13:30:22 2024 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Dec 16 17:47:14 2024 +0100

    cool#7406 Inform lokit side about the grid state.
    
    When grid in impress or draw is turned on, we need to inform libreofficekit.
    So it can show relevant UI and act accordingly. Same goes for griduse 
command.
    
    Also add a test for the new state callbacks.
    
    Change-Id: Ia5737ca0088e434f826eb7c40b0bec59049432af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178578
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx 
b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 5f0a3b747a64..d0daf44d25f3 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1338,6 +1338,32 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testTdf105502)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aLastCell.mnRow);
 }
 
+CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testShowAndUseGridCallbacks)
+{
+    /*
+        Showing and hiding grid is done via one command. Command toggles the 
grid state.
+        Also "snapping the objects to grid" feature is toggled via one command.
+        Here we switch on and off these 2 features and check the callbacks.
+    */
+
+    SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
+    
pXImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+
+    ViewCallback aView;
+
+    dispatchCommand(mxComponent, ".uno:GridVisible", 
uno::Sequence<beans::PropertyValue>());
+    CPPUNIT_ASSERT(std::find(aView.m_aStateChanged.begin(), 
aView.m_aStateChanged.end(), ".uno:GridVisible=true") != 
aView.m_aStateChanged.end());
+
+    dispatchCommand(mxComponent, ".uno:GridVisible", 
uno::Sequence<beans::PropertyValue>());
+    CPPUNIT_ASSERT(std::find(aView.m_aStateChanged.begin(), 
aView.m_aStateChanged.end(), ".uno:GridVisible=false") != 
aView.m_aStateChanged.end());
+
+    dispatchCommand(mxComponent, ".uno:GridUse", 
uno::Sequence<beans::PropertyValue>());
+    CPPUNIT_ASSERT(std::find(aView.m_aStateChanged.begin(), 
aView.m_aStateChanged.end(), ".uno:GridUse=false") != 
aView.m_aStateChanged.end());
+
+    dispatchCommand(mxComponent, ".uno:GridUse", 
uno::Sequence<beans::PropertyValue>());
+    CPPUNIT_ASSERT(std::find(aView.m_aStateChanged.begin(), 
aView.m_aStateChanged.end(), ".uno:GridUse=true") != 
aView.m_aStateChanged.end());
+}
+
 CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentCallbacks)
 {
     // Load the document.
diff --git a/sd/qa/unit/tiledrendering/tiledrenderingmodeltestbase.cxx 
b/sd/qa/unit/tiledrendering/tiledrenderingmodeltestbase.cxx
index 8d134ae2143f..19905add0af7 100644
--- a/sd/qa/unit/tiledrendering/tiledrenderingmodeltestbase.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrenderingmodeltestbase.cxx
@@ -248,6 +248,7 @@ public:
     bool m_bViewSelectionSet;
     boost::property_tree::ptree m_aCommentCallbackResult;
     OString m_ShapeSelection;
+    std::vector<std::string> m_aStateChanged;
     std::map<std::string, boost::property_tree::ptree> m_aStateChanges;
     TestLokCallbackWrapper m_callbackWrapper;
 
@@ -367,6 +368,7 @@ public:
                 std::stringstream aStream(pPayload);
                 if (!aStream.str().starts_with("{"))
                 {
+                    m_aStateChanged.push_back(aStream.str());
                     break;
                 }
 
diff --git a/sd/source/ui/view/drviewsg.cxx b/sd/source/ui/view/drviewsg.cxx
index c0e71e05ad7e..149894fcd0e2 100644
--- a/sd/source/ui/view/drviewsg.cxx
+++ b/sd/source/ui/view/drviewsg.cxx
@@ -31,6 +31,10 @@
 
 #include <app.hrc>
 
+#include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
 #include <drawdoc.hxx>
 #include <sdmod.hxx>
 #include <optsitem.hxx>
@@ -119,12 +123,24 @@ void DrawViewShell::ExecOptionsBar( SfxRequest& rReq )
         case SID_GRID_VISIBLE: // not here yet!
         {
             pOptions->SetGridVisible( !mpDrawView->IsGridVisible() );
+
+            if (comphelper::LibreOfficeKit::isActive())
+            {
+                OString state = !mpDrawView->IsGridVisible() ? 
".uno:GridVisible=true"_ostr: ".uno:GridVisible=false"_ostr;
+                
SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
state);
+            }
         }
         break;
 
         case SID_GRID_USE:
         {
             pOptions->SetUseGridSnap( !mpDrawView->IsGridSnap() );
+
+            if (comphelper::LibreOfficeKit::isActive())
+            {
+                OString state = !mpDrawView->IsGridSnap() ? 
".uno:GridUse=true"_ostr: ".uno:GridUse=false"_ostr;
+                
SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
state);
+            }
         }
         break;
 

Reply via email to