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 038c4a42834014b421a2e8a99ae436eb2dc8f8c5
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sun May 15 10:05:54 2022 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Oct 26 08:18:55 2022 +0200

    lok: support embedded media
    
    Change-Id: Ie8f3ed188cec0050a10a5d49325756931b902ef1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141807
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ee6802ebb24e..b0ebc21138eb 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1545,6 +1545,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 3bc0ad940b18..1e9821204c0b 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 1c5a94966776..eaa7abe9785c 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 020f4d56c947..6199fcaffe5b 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 fba48d9293ef..ce4bd1890619 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1485,6 +1485,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 e0cdb25505ec..b168538fe0c8 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -892,4 +892,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 8539c78c7c94..3e4383c89137 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>
@@ -1153,6 +1154,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() == SdrObjKind::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 421ead2fe082..e2e4731e129a 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -29,6 +29,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>
 
@@ -458,4 +462,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.getOpenWidth());
+        json.put("h", aRect.getOpenHeight());
+
+        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 90723501be91..f579a50911e4 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>
@@ -628,6 +629,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