desktop/source/lib/init.cxx                  |    1 +
 include/LibreOfficeKit/LibreOfficeKitEnums.h |   19 +++++++++++++++++++
 include/sfx2/lokhelper.hxx                   |    4 ++++
 include/svx/svdomedia.hxx                    |    3 +++
 libreofficekit/source/gtk/lokdocview.cxx     |    1 +
 sfx2/source/view/lokhelper.cxx               |    9 +++++++++
 svx/source/svdraw/svdmrkv.cxx                |    9 +++++++++
 svx/source/svdraw/svdomedia.cxx              |   25 +++++++++++++++++++++++++
 svx/source/svdraw/svdxcgv.cxx                |   13 +++++++++++++
 9 files changed, 84 insertions(+)

New commits:
commit 8c20411adedb38453968f9ba5dbbbf196a51bd9d
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sun May 15 10:05:54 2022 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Oct 24 08:16:55 2022 +0200

    lok: support embedded media
    
    Signed-off-by: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
    Change-Id: Ie8f3ed188cec0050a10a5d49325756931b902ef1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141502
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c2e8a285663a..1621d8a70e02 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1577,6 +1577,7 @@ void CallbackFlushHandler::queue(const int type, 
CallbackData& aCallbackData)
             type != LOK_CALLBACK_TEXT_SELECTION &&
             type != LOK_CALLBACK_TEXT_SELECTION_START &&
             type != LOK_CALLBACK_TEXT_SELECTION_END &&
+            type != LOK_CALLBACK_MEDIA_SHAPE &&
             type != LOK_CALLBACK_REFERENCE_MARKS)
         {
             SAL_INFO("lok", "Skipping while painting [" << type << "]: [" << 
aCallbackData.getPayload() << "].");
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h 
b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 8323b160a00c..bd6a15243c48 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -882,6 +882,23 @@ typedef enum
      *
      */
     LOK_CALLBACK_FONTS_MISSING = 57,
+
+    /**
+     * Insertion, removal, movement, and selection of a media shape.
+     * The payload is a json with the relevant details.
+     *
+     *      {
+     *          "action": "insert",
+     *          "id": 123456,
+     *          "url": "file:// ..."
+     *          "x": ...,
+     *          "y": ...,
+     *      }
+     *
+     *      where the "svg" property is a string containing an svg document
+     *      which is a representation of the pie segment.
+     */
+    LOK_CALLBACK_MEDIA_SHAPE = 58,
 }
 LibreOfficeKitCallbackType;
 
@@ -1026,6 +1043,8 @@ static inline const char* lokCallbackTypeToString(int 
nType)
         return "LOK_CALLBACK_PRINT_RANGES";
     case LOK_CALLBACK_FONTS_MISSING:
         return "LOK_CALLBACK_FONTS_MISSING";
+    case LOK_CALLBACK_MEDIA_SHAPE:
+        return "LOK_CALLBACK_MEDIA_SHAPE";
     }
 
     assert(!"Unknown LibreOfficeKitCallbackType type.");
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 7e899766785d..b8d584ac8ecc 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -157,6 +157,10 @@ 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);
+
 private:
     static int createView(SfxViewFrame* pViewFrame, ViewShellDocId docId);
 };
diff --git a/include/svx/svdomedia.hxx b/include/svx/svdomedia.hxx
index d80ec5a577b9..c47dda4d4717 100644
--- a/include/svx/svdomedia.hxx
+++ b/include/svx/svdomedia.hxx
@@ -72,6 +72,9 @@ 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/libreofficekit/source/gtk/lokdocview.cxx 
b/libreofficekit/source/gtk/lokdocview.cxx
index d138aa0b1630..9e9e5195d307 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1479,6 +1479,7 @@ callback (gpointer pData)
     case LOK_CALLBACK_SC_FOLLOW_JUMP:
     case LOK_CALLBACK_PRINT_RANGES:
     case LOK_CALLBACK_FONTS_MISSING:
+    case LOK_CALLBACK_MEDIA_SHAPE:
     {
         // TODO: Implement me
         break;
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index d65303762e8a..9aab08583589 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -894,4 +894,13 @@ 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());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index eeed5b3ddcf4..b788c2a060c3 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -23,6 +23,7 @@
 #include <svx/svdpagv.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/svdotable.hxx>
+#include <svx/svdomedia.hxx>
 
 #include <osl/diagnose.h>
 #include <osl/thread.h>
@@ -1146,6 +1147,14 @@ void 
SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S
             
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();
+        }
     }
 }
 
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index cb78eee47766..2f5124dc8ee7 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -30,6 +30,10 @@
 #include <ucbhelper/content.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/storagehelper.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <boost/property_tree/json_parser.hpp>
 
 #include <vcl/svapp.hxx>
 
@@ -428,4 +432,25 @@ void SdrMediaObj::mediaPropertiesChanged( const 
::avmedia::MediaItem& rNewProper
     }
 }
 
+void SdrMediaObj::notifyPropertiesForLOKit()
+{
+    if (!m_xImpl->m_MediaProperties.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", m_xImpl->m_MediaProperties.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);
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index 9a2ca91a2c92..c5281b534f59 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -27,6 +27,7 @@
 #include <svx/svdoutl.hxx>
 #include <svx/svdundo.hxx>
 #include <svx/svdograf.hxx>
+#include <svx/svdomedia.hxx>
 #include <svx/svdoole2.hxx>
 #include <svx/svdorect.hxx>
 #include <svx/svdopage.hxx>
@@ -624,6 +625,18 @@ Graphic SdrExchangeView::GetObjGraphic(const SdrObject& 
rSdrObject)
             aRet = *pSdrOle2Obj->GetGraphic();
         }
     }
+    else
+    {
+        // Support extracting a snapshot from video media, if possible.
+        const SdrMediaObj* pSdrMediaObj = dynamic_cast<const 
SdrMediaObj*>(&rSdrObject);
+        if (pSdrMediaObj)
+        {
+            const css::uno::Reference<css::graphic::XGraphic>& xGraphic
+                = pSdrMediaObj->getSnapshot();
+            if (xGraphic.is())
+                aRet = Graphic(xGraphic);
+        }
+    }
 
     // if graphic could not be retrieved => go the hard way and create a 
MetaFile
     if((GraphicType::NONE == aRet.GetType()) || (GraphicType::Default == 
aRet.GetType()))

Reply via email to