sc/inc/postit.hxx              |    9 +++++++++
 sc/source/core/data/postit.cxx |   27 +++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

New commits:
commit 3cc72a1880d1fe2507892eabeb979aa0938dadc5
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Aug 11 13:14:36 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Aug 12 17:22:21 2023 +0200

    add a CreateNoteFromObjectProperties
    
    which an importer can use to insert a note and defer instantiating an
    SdrCaption until the user activates it
    
    Change-Id: I7d4afe7857d4ee9c49e7b43c5f94150b72ce9a95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155612
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index c6ac3b5a4bd4..c2a5cc9a60ad 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -242,6 +242,15 @@ public:
                             const OutlinerParaObject& rOutlinerObj,
                             const tools::Rectangle& rCaptionRect, bool bShown 
);
 
+    // similar to above, except rPropertyNames/rPropertyValues contain the
+    // uno properties for the caption object formatting.
+    static ScPostIt*    CreateNoteFromObjectProperties(
+                            ScDocument& rDoc, const ScAddress& rPos,
+                            const css::uno::Sequence<OUString>& rPropertyNames,
+                            const css::uno::Sequence<css::uno::Any>& 
rPropertyValues,
+                            const OutlinerParaObject& rOutlinerObj,
+                            const tools::Rectangle& rCaptionRect, bool bShown 
);
+
     /** Creates a cell note based on the passed string and inserts it into the
         document.
 
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 378323338eb1..cdcc03e4999d 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -25,6 +25,7 @@
 #include <unotools/useroptions.hxx>
 #include <svx/svdocapt.hxx>
 #include <svx/svdpage.hxx>
+#include <svx/unoshape.hxx>
 #include <editeng/outlobj.hxx>
 #include <editeng/editobj.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
@@ -427,6 +428,10 @@ ScNoteCaptionCreator::ScNoteCaptionCreator( ScDocument& 
rDoc, const ScAddress& r
 struct ScCaptionInitData
 {
     std::optional< SfxItemSet > moItemSet;  /// Caption object formatting.
+
+    uno::Sequence<OUString> maPropertyNames; /// Alternative import filter 
Caption object formatting property names
+    uno::Sequence<uno::Any> maPropertyValues; /// Alternative import filter 
Caption object formatting property values
+
     std::optional< OutlinerParaObject > mxOutlinerObj; /// Text object with 
all text portion formatting.
     OUString            maStyleName;        /// Drawing style associated with 
the caption object.
     OUString            maSimpleText;       /// Simple text without formatting.
@@ -679,6 +684,13 @@ void ScPostIt::CreateCaptionFromInitData( const ScAddress& 
rPos ) const
             ScCaptionUtil::SetExtraItems(*maNoteData.mxCaption, 
*xInitData->moItemSet);
     }
 
+    if (xInitData->maPropertyNames.getLength())
+    {
+        rtl::Reference<SvxShapeText> 
xAnnoShape(dynamic_cast<SvxShapeText*>(maNoteData.mxCaption->getUnoShape().get()));
 // SvxShapeText
+        assert(xAnnoShape && "will not be null");
+        
static_cast<SvxShape*>(xAnnoShape.get())->setPropertyValues(xInitData->maPropertyNames,
 xInitData->maPropertyValues);
+    }
+
     // set position and size of the caption object
     if( xInitData->mbDefaultPosSize )
     {
@@ -964,6 +976,21 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData(
     return InsertNote(rDoc, rPos, std::move(aNoteData), 
/*bAlwaysCreateCaption*/false, 0/*nPostItId*/);
 }
 
+ScPostIt* ScNoteUtil::CreateNoteFromObjectProperties(
+        ScDocument& rDoc, const ScAddress& rPos,
+        const uno::Sequence<OUString>& rPropertyNames,
+        const uno::Sequence<uno::Any>& rPropertyValues,
+        const OutlinerParaObject& rOutlinerObj, const tools::Rectangle& 
rCaptionRect,
+        bool bShown )
+{
+    ScNoteData aNoteData(CreateNoteData(rDoc, rPos, rOutlinerObj, 
rCaptionRect, bShown));
+    ScCaptionInitData& rInitData = *aNoteData.mxInitData;
+    rInitData.maPropertyNames = rPropertyNames;
+    rInitData.maPropertyValues = rPropertyValues;
+
+    return InsertNote(rDoc, rPos, std::move(aNoteData), 
/*bAlwaysCreateCaption*/false, 0/*nPostItId*/);
+}
+
 ScPostIt* ScNoteUtil::InsertNote(ScDocument& rDoc, const ScAddress& rPos, 
ScNoteData&& rNoteData,
                                  bool bAlwaysCreateCaption, sal_uInt32 
nPostItId)
 {

Reply via email to