sc/qa/unit/data/ods/tdf140866.ods      |binary
 sc/qa/unit/scshapetest.cxx             |   50 +++++++++++++++++++++++++++++++++
 sc/source/core/data/drwlayer.cxx       |    4 +-
 sd/source/ui/unoidl/DrawController.cxx |    2 -
 4 files changed, 54 insertions(+), 2 deletions(-)

New commits:
commit 7b33705f535eaff0e9c423877dbaff717b391063
Author:     Balazs Varga <[email protected]>
AuthorDate: Fri Sep 26 17:03:06 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Sep 29 16:55:13 2025 +0200

    tdf#140866 - sc fix cell comments disappear after ods saving
    
    They disappeared because before saving the file to ods
    some other drawing objects very copied and pasted on the sheet
    which caused a recalculation of all the cell anchored drawing object's
    anchor position with SetCellAnchoredFromPosition since commit:
    545737df40880875304bffc3f49800d1d2e99723
    No need to recalculate the cell anchor position of Caption objects
    since their anchor position is handled differently.
    
    Change-Id: I83d54075974d9a7c2676af23f285e621afe0d523
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191548
    Tested-by: Gabor Kelemen <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <[email protected]>
    (cherry picked from commit d932a383766b6133ffe9ebf077f95cc328807b1b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191608
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit 161311deff7d1efaa7cca1f06b74df4d1b5f7efb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191619
    Reviewed-by: Ilmari Lauhakangas <[email protected]>
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Xisco Fauli <[email protected]>

diff --git a/sc/qa/unit/data/ods/tdf140866.ods 
b/sc/qa/unit/data/ods/tdf140866.ods
new file mode 100644
index 000000000000..5b3c73161782
Binary files /dev/null and b/sc/qa/unit/data/ods/tdf140866.ods differ
diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx
index fbea25178581..7431f13a9f1e 100644
--- a/sc/qa/unit/scshapetest.cxx
+++ b/sc/qa/unit/scshapetest.cxx
@@ -25,6 +25,7 @@
 #include <drwlayer.hxx>
 #include <fuconcustomshape.hxx>
 #include <fuconuno.hxx>
+#include <postit.hxx>
 #include <tabvwsh.hxx>
 #include <userdat.hxx>
 
@@ -78,6 +79,17 @@ static SdrObject* lcl_getSdrObjectbyName(ScDocument& rDoc, 
std::u16string_view r
     return pObj;
 }
 
+static void lcl_SelectObjectByName(ScTabViewShell& rViewShell, 
std::u16string_view rObjName)
+{
+    bool bFound = rViewShell.SelectObject(rObjName);
+    CPPUNIT_ASSERT_MESSAGE(
+        OString(OUStringToOString(rObjName, RTL_TEXTENCODING_UTF8) + " not 
found.").getStr(),
+        bFound);
+
+    
CPPUNIT_ASSERT(rViewShell.GetViewData().GetScDrawView()->GetMarkedObjectList().GetMarkCount()
+                   != 0);
+}
+
 CPPUNIT_TEST_FIXTURE(ScShapeTest, testTdf144242_OpenBezier_noSwapWH)
 {
     // Shapes, which have rotation incorporated in their points, got 
erroneously width-height
@@ -1373,6 +1385,44 @@ CPPUNIT_TEST_FIXTURE(ScShapeTest, 
testTdf167450_copySheet)
     CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aRectSource, 
pObjTarget->GetLogicRect(), 1);
 }
 
+CPPUNIT_TEST_FIXTURE(ScShapeTest, testTdf140866)
+{
+    // Load a document, which has a comment in cell $sheet2.$A$1, and a custom 
shape in cell
+    // $sheet2.$B$11. When the shape from $sheet2.$B$11 was copied and pasted 
to $sheet2.$D$9,
+    // the anchor position of comment is changed and after saved to ods the 
comment was gone.
+    createScDoc("ods/tdf140866.ods");
+    ScDocument* pDoc = getScDoc();
+
+    // Check that we have the comment on A1
+    ScPostIt* pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(pNote);
+    CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText());
+
+    goToCell(u"$Sheet2.$B$11"_ustr);
+    lcl_SelectObjectByName(*getViewShell(), u"Shape 1");
+
+    // Copy and paste
+    dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
+    goToCell(u"$Sheet2.$D$9"_ustr);
+    dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
+
+    // Check that we still have the comment on A1
+    pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(pNote);
+    CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText());
+
+    // Save, reload
+    saveAndReload(u"calc8"_ustr);
+    pDoc = getScDoc();
+    // Check that we still have the comment on A1 after save&reload
+    pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    // Without the fix in place the comment was gone and test would have 
failed with:
+    // assertion failed
+    // - Expression : pNote
+    CPPUNIT_ASSERT(pNote);
+    CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index d41f21e86d71..b5355bf0b0f0 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -2693,7 +2693,9 @@ bool ScDrawLayer::IsCellAnchored( const SdrObject& rObj )
 {
     // Cell anchored object always has a user data, to store the anchor cell
     // info. If it doesn't then it's page-anchored.
-    return GetFirstUserDataOfType(&rObj, SC_UD_OBJDATA) != nullptr;
+    // tdf#140866: Caption objects anchor position are handled differently.
+    return GetFirstUserDataOfType(&rObj, SC_UD_OBJDATA) != nullptr
+           && rObj.GetObjIdentifier() != SdrObjKind::Caption;
 }
 
 bool ScDrawLayer::IsResizeWithCell( const SdrObject& rObj )
commit c2c6290671c3c3696a07af28d8b50641fcedde2a
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon Sep 29 10:18:15 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Sep 29 16:55:06 2025 +0200

    tdf#168599: don't create Any from a direct reference to an interface
    
    An overlook from commit 3cb0678a9cac9a681903b5a082d1c5dd5f25f665
    (fix dodgy DrawController::fireChangeLayer code, 2025-03-05).
    
    This goes through this ctor:
    
      template <typename T>
      inline Any::Any( T const & value )
      {
          ::uno_type_any_construct(
              this, const_cast<T *>(&value),
              ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
              cpp_acquire );
      }
    
    which gets a valid type for the value (typelib_TypeClass_INTERFACE),
    and then uses a raw pointer in uno_type_any_construct. This crashes
    (0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF)
    because _copyConstructAnyFromData assumes typelib_TypeClass_INTERFACE
    case to have a pointer to pointer (a pointer to css::uno::Reference,
    which is itseld a lone pointer), with this stack:
    
      sdlo.dll!com::sun::star::uno::cpp_acquire(void * pCppI) Line 47
      cppu3.dll!cppu::_acquire(void * p, void(*)(void *) acquire) Line 70
      cppu3.dll!cppu::_copyConstructAnyFromData(_uno_Any * pDestAny, void * 
pSource, _typelib_TypeDescriptionReference * pType, _typelib_TypeDescription * 
pTypeDescr, void(*)(void *) acquire, _uno_Mapping * mapping) Line 243
      cppu3.dll!cppu::_copyConstructAny(_uno_Any * pDestAny, void * pSource, 
_typelib_TypeDescriptionReference * pType, _typelib_TypeDescription * 
pTypeDescr, void(*)(void *) acquire, _uno_Mapping * mapping) Line 284
      cppu3.dll!uno_type_any_construct(_uno_Any * pDest, void * pSource, 
_typelib_TypeDescriptionReference * pType, void(*)(void *) acquire) Line 69
      
sdlo.dll!com::sun::star::uno::Any::Any<com::sun::star::drawing::XLayer>(const 
com::sun::star::drawing::XLayer & value) Line 68
      sdlo.dll!sd::DrawController::fireChangeLayer(const 
com::sun::star::uno::Reference<com::sun::star::drawing::XLayer> & xNewLayer) 
Line 473
      sdlo.dll!sd::DrawViewShell::SetActiveTabLayerIndex(int nIndex) Line 635
      sdlo.dll!sd::FuPoor::SwitchLayer(long nOffset) Line 1060
      sdlo.dll!sd::FuPoor::KeyInput(const KeyEvent & rKEvt) Line 493
      sdlo.dll!sd::FuDraw::KeyInput(const KeyEvent & rKEvt) Line 432
      sdlo.dll!sd::FuSelection::KeyInput(const KeyEvent & rKEvt) Line 1056
      sdlo.dll!sd::ViewShell::KeyInput(const KeyEvent & rKEvt, sd::Window * 
pWin) Line 530
      sdlo.dll!sd::DrawViewShell::KeyInput(const KeyEvent & rKEvt, sd::Window * 
pWin) Line 252
      sdlo.dll!sd::Window::KeyInput(const KeyEvent & rKEvt) Line 226
      vcllo.dll!ImplHandleKey(vcl::Window * pWindow, NotifyEventType nSVEvent, 
unsigned short nKeyCode, unsigned short nCharCode, unsigned short nRepeat, bool 
bForward) Line 1236
      vcllo.dll!ImplWindowFrameProc(vcl::Window * _pWindow, SalEvent nEvent, 
const void * pEvent) Line 2742
      vcllo.dll!SalFrame::CallCallback(SalEvent nEvent, const void * pEvent) 
Line 310
      vclplug_winlo.dll!ImplHandleKeyMsg(HWND__ * hWnd, unsigned int nMsg, 
unsigned __int64 wParam, __int64 lParam, __int64 & rResult) Line 4011
      vclplug_winlo.dll!SalFrameWndProc(HWND__ * hWnd, unsigned int nMsg, 
unsigned __int64 wParam, __int64 lParam, bool & rDef) Line 5925
      vclplug_winlo.dll!SalFrameWndProcW(HWND__ * hWnd, unsigned int nMsg, 
unsigned __int64 wParam, __int64 lParam) Line 6226
      user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,__int64 
(*)(struct tagWND *,unsigned int,unsigned __int64,__int64),struct HWND__ *,enum 
_WM_VALUE,unsigned __int64,__int64,void *,int)
      user32.dll!CallWindowProcW()
      opengl32.dll!wglWndProc()
      user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,__int64 
(*)(struct tagWND *,unsigned int,unsigned __int64,__int64),struct HWND__ *,enum 
_WM_VALUE,unsigned __int64,__int64,void *,int)
      user32.dll!DispatchMessageWorker()
      vclplug_winlo.dll!ImplSalDispatchMessage(const tagMSG * pMsg) Line 431
      vclplug_winlo.dll!ImplSalYield(bool bWait, bool bHandleAllCurrentEvents) 
Line 500
      vclplug_winlo.dll!WinSalInstance::DoYield(bool bWait, bool 
bHandleAllCurrentEvents) Line 537
      vcllo.dll!ImplYield(bool i_bWait, bool i_bAllEvents) Line 389
      vcllo.dll!Application::Yield() Line 492
      vcllo.dll!Application::Execute() Line 365
      sofficeapp.dll!desktop::Desktop::Main() Line 1682
      vcllo.dll!ImplSVMain() Line 230
      vcllo.dll!SVMain() Line 249
      sofficeapp.dll!soffice_main() Line 122
      soffice.bin!sal_main() Line 51
      soffice.bin!main(int argc, char * * argv) Line 49
      soffice.bin!invoke_main() Line 79
      soffice.bin!__scrt_common_main_seh() Line 288
      soffice.bin!__scrt_common_main() Line 331
      soffice.bin!mainCRTStartup(void * __formal) Line 17
      kernel32.dll!BaseThreadInitThunk()
      ntdll.dll!RtlUserThreadStart()
    
    Change-Id: Ib61823e74b260d262adbaa5d3d63232b599d3cac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191593
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 16a0b42a4f79a20a2aaf8dd443c55b81a8084351)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191607
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit ecb65b032dc169cda9e5beed2d2a61ab47619bdb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191616
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Xisco Fauli <[email protected]>
    Reviewed-by: Ilmari Lauhakangas <[email protected]>

diff --git a/sd/source/ui/unoidl/DrawController.cxx 
b/sd/source/ui/unoidl/DrawController.cxx
index c3031a8f232c..43d5cce3e704 100644
--- a/sd/source/ui/unoidl/DrawController.cxx
+++ b/sd/source/ui/unoidl/DrawController.cxx
@@ -457,7 +457,7 @@ void DrawController::fireChangeLayer( const 
css::uno::Reference< css::drawing::X
     {
         sal_Int32 nHandle = PROPERTY_ACTIVE_LAYER;
 
-        Any aNewValue ( *xNewLayer);
+        Any aNewValue (xNewLayer);
 
         Any aOldValue ;
 

Reply via email to