include/sfx2/lokhelper.hxx      |    4 ----
 include/svx/svdomedia.hxx       |    3 ---
 sfx2/source/view/lokhelper.cxx  |    9 ---------
 svx/source/svdraw/svdmrkv.cxx   |   31 +++++++++++++++++++++----------
 svx/source/svdraw/svdomedia.cxx |   23 -----------------------
 5 files changed, 21 insertions(+), 49 deletions(-)

New commits:
commit 0cea676ceb46dcdb9ba739db79dbc6f0d7b3dc29
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sat Feb 11 14:53:44 2023 -0500
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Feb 14 11:56:22 2023 +0000

    lok: only publish MEDIA_SHAPE to selecting view
    
    We now publish the url for the media shape
    in the LOK_CALLBACK_GRAPHIC_SELECTION message.
    
    This has many advantages, most notably that it
    only sends the URL to the view selecting the
    media. Also, it is now easier to handle
    the message as there is no need for both
    a LOK_CALLBACK_GRAPHIC_SELECTION and
    a LOK_CALLBACK_MEDIA_SHAPE. However, the
    latter is still defined as we might still
    use it at some point.
    
    Signed-off-by: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
    Change-Id: I8d4b8794d8e590628630f2b0bfbfb5debe02515f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146848
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 16e48c791d65..95eb0a9f9f6f 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -172,10 +172,6 @@ public:
     /// Helper for diagnosing run-time problems
     static void dumpState(rtl::OStringBuffer &rState);
 
-    /// Notify all views of a media update.
-    /// This could be a new insertion or property modifications to an existing 
one.
-    static void notifyMediaUpdate(boost::property_tree::ptree& json);
-
     /// Process the mouse event in the currently active in-place component (if 
any).
     /// Returns true if the event has been processed, and no further 
processing is necessary.
     static bool testInPlaceComponentMouseEventHit(SfxViewShell* pViewShell, 
int nType, int nX,
diff --git a/include/svx/svdomedia.hxx b/include/svx/svdomedia.hxx
index 36b00f276d80..629ad980e6b3 100644
--- a/include/svx/svdomedia.hxx
+++ b/include/svx/svdomedia.hxx
@@ -75,9 +75,6 @@ public:
 
         virtual bool shouldKeepAspectRatio() const override { return true; }
 
-        /// When Lokit is enabled, notify the media details.
-        void notifyPropertiesForLOKit();
-
 private:
         void                mediaPropertiesChanged( const 
::avmedia::MediaItem& rNewState );
         virtual std::unique_ptr<sdr::contact::ViewContact> 
CreateObjectSpecificViewContact() override;
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index e61263acc8c6..166aa124777e 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -960,15 +960,6 @@ void SfxLokHelper::dumpState(rtl::OStringBuffer &rState)
     }
 }
 
-void SfxLokHelper::notifyMediaUpdate(boost::property_tree::ptree& json)
-{
-    std::stringstream aStream;
-    boost::property_tree::write_json(aStream, json, /*pretty=*/ false);
-    const std::string str = aStream.str();
-
-    SfxLokHelper::notifyAllViews(LOK_CALLBACK_MEDIA_SHAPE, str.c_str());
-}
-
 bool SfxLokHelper::testInPlaceComponentMouseEventHit(SfxViewShell* pViewShell, 
int nType, int nX,
                                                      int nY, int nCount, int 
nButtons,
                                                      int nModifier, double 
fScaleX, double fScaleY,
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index f48051e974c0..bd0fe4c8993c 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -825,10 +825,12 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
     }
 
     {
+        OStringBuffer aExtraInfo;
         OString sSelectionText;
         OString sSelectionTextView;
         boost::property_tree::ptree aTableJsonTree;
         boost::property_tree::ptree aGluePointsTree;
+        const bool bMediaObj = (mpMarkedObj && mpMarkedObj->GetObjIdentifier() 
== OBJ_MEDIA);
         bool bTableSelection = false;
         bool bConnectorSelection = false;
 
@@ -841,6 +843,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
         {
             bConnectorSelection = dumpGluePointsToJSON(aGluePointsTree);
         }
+
         if (GetMarkedObjectCount())
         {
             SdrMark* pM = GetSdrMarkByIndex(0);
@@ -850,7 +853,6 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
             // (SwVirtFlyDrawObj with a SwGrfNode)
             bool bWriterGraphic = pO->HasLimitedRotation();
 
-            OStringBuffer aExtraInfo;
             OString handleArrayStr;
 
             aExtraInfo.append("{\"id\":\"");
@@ -1009,6 +1011,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
                     }
                 }
             }
+
             if (!bTableSelection && !pOtherShell && maHdlList.GetHdlCount())
             {
                 boost::property_tree::ptree responseJSON;
@@ -1106,12 +1109,27 @@ void 
SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S
                 sSelectionText = aSelection.toString() +
                     ", " + OString::number(nRotAngle.get());
             }
+
             if (!aExtraInfo.isEmpty())
             {
                 sSelectionTextView = sSelectionText + ", " + 
aExtraInfo.toString() + "}";
+
+                if (bMediaObj && pOtherShell == nullptr)
+                {
+                    // Add the URL only if we hav a Media Object and
+                    // we are the the selecting view.
+                    SdrMediaObj* mediaObj = 
dynamic_cast<SdrMediaObj*>(mpMarkedObj);
+                    if (mediaObj)
+                    {
+                        aExtraInfo.append(", \"url\": \"");
+                        aExtraInfo.append(mediaObj->getTempURL().toUtf8());
+                        aExtraInfo.append("\"");
+                    }
+                }
+
                 aExtraInfo.append(handleArrayStr);
                 aExtraInfo.append("}");
-                sSelectionText += ", " + aExtraInfo.makeStringAndClear();
+                sSelectionText += ", " + aExtraInfo.toString();
             }
         }
 
@@ -1153,15 +1171,8 @@ void 
SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S
             // We have a new selection, so both pViewShell and the
             // other views want to know about it.
             
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_GRAPHIC_SELECTION, 
sSelectionText.getStr());
-            SfxLokHelper::notifyOtherViews(pViewShell, 
LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", sSelectionTextView);
-        }
 
-        if (comphelper::LibreOfficeKit::isActive() && mpMarkedObj
-            && mpMarkedObj->GetObjIdentifier() == OBJ_MEDIA)
-        {
-            SdrMediaObj* mediaObj = dynamic_cast<SdrMediaObj*>(mpMarkedObj);
-            if (mediaObj)
-                mediaObj->notifyPropertiesForLOKit();
+            SfxLokHelper::notifyOtherViews(pViewShell, 
LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", sSelectionTextView);
         }
     }
 }
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 75bfce24428c..39d455c38253 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -442,27 +442,4 @@ void SdrMediaObj::mediaPropertiesChanged( const 
::avmedia::MediaItem& rNewProper
     }
 }
 
-void SdrMediaObj::notifyPropertiesForLOKit()
-{
-#if HAVE_FEATURE_AVMEDIA
-    if (!getTempURL().isEmpty())
-    {
-        const auto mediaId = reinterpret_cast<std::size_t>(this);
-
-        boost::property_tree::ptree json;
-        json.put("action", "update");
-        json.put("id", mediaId);
-        json.put("url", getTempURL());
-
-        const tools::Rectangle aRect = o3tl::convert(maRect, 
o3tl::Length::mm100, o3tl::Length::twip);
-        json.put("x", aRect.getX());
-        json.put("y", aRect.getY());
-        json.put("w", aRect.getWidth());
-        json.put("h", aRect.getHeight());
-
-        SfxLokHelper::notifyMediaUpdate(json);
-    }
-#endif
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to